Repository navigation
Fix compiler warning about uninitialized rb_parent_color - #1484
Conversation
When compiling with GCC 15.2.1, the compiler issues a maybe-uninitialized warning with message: rb_parent_color may be used uninitialized. This is happening because the RB_CLEAR_NODE macro currently expands to rb_set_parent(node, node), which in turn attempts to read the node->rb_parent_color. In certain cases where the node has not yet been initialized, reading the rb_parent_color could return garbage. This change fixes the issue and clears the warning by updating the RB_CLEAR_NODE macro to directly set the parent pointer without reading the potential garbage color value. The new RB_CLEAR_NODE macro implementation is similar to what is used in the Linux kernel.
|
The full text of the compiler warning for reference:
|
There was a problem hiding this comment.
This change makes sense. It's basically the same as before, except the node pointer isn't also OR'd with the uninitialized rb_parent_color.
When it's used, e.g., in track.c by simple_track_new, it's done against memory allocated with xnew, which comes from malloc.
When modifying to the tree, the color is set explicitly.
When compiling with GCC 15.2.1, the compiler issues a maybe-uninitialized warning with message: rb_parent_color may be used uninitialized. This is happening because the RB_CLEAR_NODE macro currently expands to rb_set_parent(node, node), which in turn attempts to read the node->rb_parent_color. In certain cases where the node has not yet been initialized, reading the rb_parent_color could return garbage.
This change fixes the issue and clears the warning by updating the RB_CLEAR_NODE macro to directly set the parent pointer without reading the potential garbage color value. The new RB_CLEAR_NODE macro implementation is similar to what is used in the Linux kernel.