fix potential integer overflow