fix string off-by-one bugs

This fixes a few instances of incorrect usage of strncpy() and snprintf(), which are potentially exploitable buffer overflow bugs.