use buffer length, not string length