Fix crash on buffer overflow