Fix linker errors on Linux.
Fix compiler warnings on Linux.
Fix integer overflow issues on 32-bit Linux.
Fix integer overflow issues on 64-bit OS X.