Fix possible integer overflow