These were revealed by GCC's -Wconversion option. Fix types where it is easy to do so. Cast in cases we know the integer will not be truncated.