Fix some signedness issues found by -Wsign-compare -Wconversion.

(Not enabling those warnings by default since there's a lot of them.)