GNOME Bugzilla – Bug 732003
gnode: Eliminate implicit signed-to-unsigned integer conversion
Last modified: 2017-11-28 14:16:56 UTC
Patch attached. See commit message for rationale.
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
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.
Attachment 278886 [details] pushed as ae78950 - gnode: Eliminate implicit signed-to-unsigned integer conversion