Skip to content

Commit af24e0c

Browse files
committed
Fix rb-tree init (#349)
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.
1 parent ac13c78 commit af24e0c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static map_node_t *map_create_node(void *key,
548548
size_t ksize,
549549
size_t vsize)
550550
{
551-
map_node_t *node = malloc(sizeof(map_node_t));
551+
map_node_t *node = calloc(1, sizeof(map_node_t));
552552
assert(node);
553553

554554
/* allocate memory for the keys and data */

0 commit comments

Comments
 (0)