Fixing potential wrap-around bug

Thanks to Kuldeep S. Meel for pointing this out