Message Boards Message Boards

1 Reply
3 Total Likes
View groups...
Share this post:

Does MLGetUTF8String() return a null-terminated string?

Posted 12 years ago
The C MathLink function MLGetUTF8String() returns a pointer to a UTF-8 string, the length of the string and the number of characters.  UTF-8 is desgined in a way to be compatible with null-terminated strings, and it appears that this function does return a null-terminated string, but this is not explicitly documented.

Can I safely assume that MLGetUTF8String will always return a null-terminated string, or was it just an accident that in my test it appeared to return one?  If would spare having to copy the whole string just to insert a '\0' at the end.

Note: I actually received an answer to this here from another user but I was hoping for some more 'official' reassurance, considering that this is undocumented.  Or perhaps suggest that it be documented, if possible.
POSTED BY: Szabolcs Horvát
MLGetUTF8String() is not guaranteed to return a null-terminated string and one should not rely on that behavior.    One should always copy the contents of a string returned
by MathLink into the applications own memory so that the library can free that resource as soon as possible.
POSTED BY: Steve Wilson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract