fix potential buffer overruns