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 732003 - gnode: Eliminate implicit signed-to-unsigned integer conversion
gnode: Eliminate implicit signed-to-unsigned integer conversion
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-06-21 10:29 UTC by Philip Withnall
Modified: 2017-11-28 14:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gnode: Eliminate implicit signed-to-unsigned integer conversion (1.36 KB, patch)
2014-06-21 10:30 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2014-06-21 10:29:57 UTC
Patch attached. See commit message for rationale.
Comment 1 Philip Withnall 2014-06-21 10:30:00 UTC
Created attachment 278886 [details] [review]
gnode: Eliminate implicit signed-to-unsigned integer conversion

When doing a level traverse of a GNode with depth of -1, the depth was
implicitly being converted to an unsigned integer. This worked (making
the depth limit G_MAXUINT), but was a bit mystical.

Change g_node_depth_traverse_level() to explicitly take a signed depth
and handle it appropriately.

Coverity issue: #1159465
Comment 2 Emmanuele Bassi (:ebassi) 2017-11-28 12:46:20 UTC
Review of attachment 278886 [details] [review]:

This API is quite hilarious.

The @depth parameter for `g_node_traverse()` is a signed integer, which makes your code valid; on the other hand, `g_node_depth()` returns an unsigned integer, so it would be *in theory* possible to have a tree of GNodes that has a `G_MAXUINT - 1` depth, by constantly appending nodes instead of inserting them at a given index (as `g_node_insert()` takes a signed integer position).

So if you try to traverse a tree with `G_MAXUINT - 2` descendants, you can either use -1 to get them all, or you'll only be able to traverse them up to an explicit `G_MAXINT - 1` depth.

We should bin this whole thing, because it's so fundamentally broken I don't even.
Comment 3 Philip Withnall 2017-11-28 14:16:52 UTC
Attachment 278886 [details] pushed as ae78950 - gnode: Eliminate implicit signed-to-unsigned integer conversion