GNOME Bugzilla – Bug 742124
g_data_input_stream_read_upto()'s documentation should say that the result is NULL-terminated
Last modified: 2018-02-16 11:15:43 UTC
I'm using g_data_input_stream_read_upto() to read a NULL terminated string, and before wastefully reallocating the string to add a NULL pointed, I checked the code in GLib and found that it already adds the NULL-pointer: data_until = g_malloc (found_pos + 1); res = g_input_stream_read (G_INPUT_STREAM (stream), data_until, found_pos, NULL, NULL); if (length) *length = (gsize)found_pos; g_warn_if_fail (res == found_pos); data_until[found_pos] = 0; I think g_data_input_stream_read_upto_async() does this too, but it's hard to follow the code. Anyway, I think this should be documented so people don't waste their time copying the string to NULL terminate it.
Fix pushed to master. Sorry for the delay, and thanks for the bug report. The following fix has been pushed: 2ffba0e gdatainputstream: Document the returned string is always nul-terminated
Created attachment 368411 [details] [review] gdatainputstream: Document the returned string is always nul-terminated Signed-off-by: Philip Withnall <withnall@endlessm.com> Reviewed-by: nobody