Fix some MSVC warnings.

Several fixes are warnings about truncations on 64-bit, while others are
complaints about mixed signed / unsigned integer operations.