Use buf->cur instead of -1