Avoid warnings when building for iOS

Get rid of warnings by avoiding mixing data types unnecessarily,
and by adding casts.
Merge pull request #1042 from mstorsjo/avoid-ios-build-warnings

Avoid warnings when building for iOS