Fix integer overflow

Fixes CID #966079, #966078