I have the following tree node struct that holds pointers to other tree nodes:
struct node {
// ...
struct node* children[20];
}
The idea is that I want to check whether there is node* inside the children and based and that go deeper into the tree. So when I allocate the node I want to have children with 20 NULL values.
Currently I am not doin
- How should I allocate this array in order to not get errors like
Conditional jump or move depends on uninitialised value(s)(Valgrind)? - Would it be better to use
struct node** childrenand allocate fixed size each time I allocate a new node?
EDIT: Example of one place where Valgrind complains:
for(int i=0;i<20;i++)
if(node->children[i] != NULL)
do_something_with_the_node(node->children[i]);
callocinstead ofmalloc. Or usememsetto set all contents to zero.Conditional jump or move depends on uninitialised value(s)reported by valgrind means that you have anifstatement, in which you're comparingnode[x], right? Can you post that code too?calloc()to set pointers toNULL.