James Curran said:
By the time it's reached interop, it's already gone through marshalling,
where it could have added the nul-terminator (at the same time it removes
the length).
Well, it can do that in cases where the marshalling is copying the
data. When it's not copying the data, the null already needs to be
there, surely - or there at least needs to be enough space for it. (I
don't believe the length is removed, so much as the pointer passed to
unmanaged code is the address of the first character of the string.)
Maybe I'm wrong and the contents is always copied though. It seems a
shame if this is the case - and I'm pretty sure that the null always
*is* there. The space taken up by the character data is always a
multiple of 4 bytes, and the way I've seen it expand suggests that
there's always at least *room* for the null.