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 719395 - GPtrArray add g_ptr_array_insert
GPtrArray add g_ptr_array_insert
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-11-27 05:42 UTC by Tristan Van Berkom
Modified: 2013-12-15 04:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Adds g_ptr_array_insert() (2.31 KB, patch)
2013-11-27 05:42 UTC, Tristan Van Berkom
none Details | Review
Adds g_ptr_array_insert() (with (gint) cast) (2.31 KB, patch)
2013-11-27 05:55 UTC, Tristan Van Berkom
committed Details | Review

Description Tristan Van Berkom 2013-11-27 05:42:30 UTC
Created attachment 262911 [details] [review]
Adds g_ptr_array_insert()

Patch to add g_ptr_array_insert() attached.
Comment 1 Allison Karlitskaya (desrt) 2013-11-27 05:46:14 UTC
Review of attachment 262911 [details] [review]:

::: glib/garray.c
@@ +1403,3 @@
+  g_return_if_fail (array);
+  g_return_if_fail (index_ >= -1);
+  g_return_if_fail (index_ <= array->len);

array->len is a uint so index_ will be promoted to uint and this comparison will be done unsigned.  it seems like that should fail if index_ were to be -1....

either way, this looks suspicious...
Comment 2 Tristan Van Berkom 2013-11-27 05:55:37 UTC
Created attachment 262912 [details] [review]
Adds g_ptr_array_insert() (with (gint) cast)

This one fixes the signed casting of the g_return_if_fail() check.

I actually had that in some code I've been using for years, and
wasn't sure anymore why the cast was there.

The g_return_if_fail() checks in this function allow the index
to be explicitly array->len (before increasing the length) or -1,
which both mean the same thing (i.e. the same as g_ptr_array_add()).

It does not allow adding pointers to an index > array->len
(i.e. it will not result in sparse arrays with NULL padding).