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 738170 - g_byte_array_new_take() doesn't initialize array->alloc
g_byte_array_new_take() doesn't initialize array->alloc
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-10-08 18:52 UTC by Aleksander Morgado
Modified: 2014-10-09 05:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (663 bytes, text/x-csrc)
2014-10-08 18:52 UTC, Aleksander Morgado
  Details
Patch (1.02 KB, patch)
2014-10-08 18:53 UTC, Aleksander Morgado
committed Details | Review

Description Aleksander Morgado 2014-10-08 18:52:21 UTC
Created attachment 288070 [details]
Test case

g_byte_array_new_take() should initialize array->alloc (the internally tracked size of the real allocation).

If array->alloc is not initialized, running g_byte_array_set_size() under gc-friendly will actually fully clear the whole internal array, not just the extra allocated size... :/

Attached test case. Without the patch, running under gc-friendly makes the test crash.

$ ./test 
$ G_DEBUG=gc-friendly ./test 
**
ERROR:test.c:21:main: assertion failed: (array->data[0] == 0xAB)
Comment 1 Aleksander Morgado 2014-10-08 18:53:04 UTC
Created attachment 288071 [details] [review]
Patch
Comment 2 Allison Karlitskaya (desrt) 2014-10-08 20:54:24 UTC
Review of attachment 288071 [details] [review]:

Nice catch.  Please commit.