From c616e30e9c4fe95efe1a1153b32254e9d6061bb0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 13 Jun 2024 00:20:26 +0900 Subject: [PATCH] strbuf: several cleanups - use FOREACH_ARRAY(), - add one missing assertion, - reduce indentation. --- src/basic/strbuf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index c08aa82e54f..e12c0f9b113 100644 --- a/src/basic/strbuf.c +++ b/src/basic/strbuf.c @@ -48,20 +48,21 @@ struct strbuf* strbuf_new(void) { } static struct strbuf_node* strbuf_node_cleanup(struct strbuf_node *node) { - size_t i; + assert(node); + + FOREACH_ARRAY(child, node->children, node->children_count) + strbuf_node_cleanup(child->child); - for (i = 0; i < node->children_count; i++) - strbuf_node_cleanup(node->children[i].child); free(node->children); return mfree(node); } /* clean up trie data, leave only the string buffer */ void strbuf_complete(struct strbuf *str) { - if (!str) + if (!str || !str->root) return; - if (str->root) - str->root = strbuf_node_cleanup(str->root); + + str->root = strbuf_node_cleanup(str->root); } /* clean up everything */ -- 2.47.3