diff -r a5b7cf49dea7 -r 7d41291b3095 src/tree.c --- a/src/tree.c Wed Dec 31 13:39:55 2025 +0100 +++ b/src/tree.c Wed Dec 31 14:58:40 2025 +0100 @@ -314,7 +314,7 @@ // node has children, push the first child onto the stack and enter it if (iter->depth >= iter->stack_capacity) { const size_t newcap = iter->stack_capacity + 8; - if (cxReallocArrayDefault(&iter->stack, newcap, sizeof(void*))) { + if (cxReallocateArrayDefault(&iter->stack, newcap, sizeof(void*))) { // we cannot return an error in this function abort(); // LCOV_EXCL_LINE } @@ -568,10 +568,18 @@ tree->collection.size++; } +void *cxTreeCreateNode(CxTree *tree, void *parent) { + void *node = cxZalloc(tree->collection.allocator, tree->node_size); + if (node == NULL) return NULL; // LCOV_EXCL_LINE + cx_tree_add(parent, node, tree_layout(tree)); + tree->collection.size++; + return node; +} + void *cxTreeAddData(CxTree *tree, void *parent, const void *data) { if (tree->loc_data < 0) return NULL; - void *node = cxZalloc(tree->collection.allocator, tree->node_size); + void *node = cxTreeCreateNode(tree, parent); if (node == NULL) return NULL; // LCOV_EXCL_LINE char *dst = node; @@ -579,8 +587,6 @@ const void *src = cxCollectionStoresPointers(tree) ? (const void*)&data : data; memcpy(dst, src, tree->collection.elem_size); - cx_tree_add(parent, node, tree_layout(tree)); - tree->collection.size++; return node; }