GNOME Bugzilla – Bug 719395
GPtrArray add g_ptr_array_insert
Last modified: 2013-12-15 04:55:06 UTC
Created attachment 262911 [details] [review] Adds g_ptr_array_insert() Patch to add g_ptr_array_insert() attached.
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...
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).