Skip to content

Commit

Permalink
Fix rb-tree init (#349)
Browse files Browse the repository at this point in the history
The struct member right_red is used in several functions, such as 
rb_node_set_right(). It has been reported by infer and LLVM static 
analyzer that right_red isn't initialized before used.

By tracing the node initialization function calls (starting from 
map_create_node), it can be seen that rb_node_set_right is the function
where right_red is attempted to be initialized, but we are indeed 
performing &1 on an uninitialized value. 

In this commit, a change to using calloc guarantees the struct members 
will be zeroed out during allocation, which in terms serves as 
initialization.
  • Loading branch information
henrybear327 committed Feb 26, 2024
1 parent ac13c78 commit af24e0c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ static map_node_t *map_create_node(void *key,
size_t ksize,
size_t vsize)
{
map_node_t *node = malloc(sizeof(map_node_t));
map_node_t *node = calloc(1, sizeof(map_node_t));
assert(node);

/* allocate memory for the keys and data */
Expand Down

0 comments on commit af24e0c

Please sign in to comment.