Fix buffer overrun when growing buffer