After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 742124 - g_data_input_stream_read_upto()'s documentation should say that the result is NULL-terminated
g_data_input_stream_read_upto()'s documentation should say that the result is...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-12-30 19:39 UTC by Brendan Long
Modified: 2018-02-16 11:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdatainputstream: Document the returned string is always nul-terminated (1.51 KB, patch)
2018-02-16 11:15 UTC, Philip Withnall
committed Details | Review

Description Brendan Long 2014-12-30 19:39:33 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.
Comment 1 Philip Withnall 2018-02-16 11:15:38 UTC
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
Comment 2 Philip Withnall 2018-02-16 11:15:43 UTC
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