when copying the left over stub, always make sure we copy the null
terminator as well. Theoretically shouldn't be a problem since we
exit the inner loop anyway and then append to the buffer and add
a new null terminator, but just to be safe, make sure the buffer
is *ALWAYS* null-terminated.
When we are at it, skip the buffer copy if we didn't consume any
input and actually compare the value against '\0' instead of just
testing for *ptr (readabillity).
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>