Fix potential buffer overflow