Write padding nulls explicitly instead of seeking forward
Write padding nulls explicitly instead of seeking forward

Change suggested by Vaclav Slavik, who explains:

The spec says that arrays are marshalled as follows:
1. length is written in 4 bytes, aligned at 4-bytes boundary
2. padding to align as needed for elements type is written
3. finally, individual elements are written
(i.e. step 2. is done even for empty arrays)

And that's indeed what MessageWriter.WriteArray() does, but the way
WritePad() is implemented (advancing stream position without writing
any data) causes any padding added to the end of the message to be
ignored. Apparently, you encountered this already, because
MessageWriter.CloseWrite() adds header padding "manually" instead of
using WritePad().

Attached patch fixes the bug by changing WritePad()
to write padding zeros instead of only seeking. I don't think there
are any performance problems with the patch: there could be if the
stream was unbuffered file stream (then I could understand how
only seeking would be better), but this code is used with MemoryStream
only.

tmds/Tmds.DBus