The code marks the end of the buffer with pend, not necessarily a zero. Making additional assumptions about the data is a latent bug, and quite easily avoided. Please fix.