Buffer length should always use size_t.
Fix some errors found by -Wconversion.