Fix MSVS compiler warnings.

Use explicit casts and appropriate types for pointer arithmetic.