Fixed compiler warnings due to unsafe type conversions.

The type conversions fixed here cause warning when building in Visual Studio as 64bit, but are potential error sources on other platforms as well.