Fix some potential buffer overflows