Fix bug causing NULLs in output

The entire buffer was being output, instead of just the filled bytes.