Fix buffer overflow bug