Fix writing of null bytes from buffer