Fix crash caused by buffer overrun