Skip to content

c-bindings: improvements to API functions returning strings

Created by: germasch

For a more detailed discussion of the underlying issue, see #1226 (closed) .

In a nutshell, the current API requires the user to pass in a preallocated buffer, but how large that buffer had to be is not known until after the call. This PR makes it possible to use those functions safely by calling the API function twice:

  • first, with a NULL buffer, so only the size will be returned
  • second, preallocate the buffer using the size from step 1, then call the function again.

While safe if used correctly, this interface is unfortunately cumbersome. It doesn't do anything about adding trailing zeros (though that could be added), either.

Merge request reports

Loading