Fix incorrect type-casting of signed to unsigned.

These incorrect type-casts were introduced by 3cb817b8.
Blindly type-casting to please the compiler is bad!
Merge pull request #1441 from jtanx/typecasting

Fix incorrect type-casting of signed to unsigned.