From: Yu Watanabe Date: Wed, 12 Jun 2024 15:20:26 +0000 (+0900) Subject: strbuf: several cleanups X-Git-Tag: v257-rc1~1122^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c616e30e9c4fe95efe1a1153b32254e9d6061bb0;p=thirdparty%2Fsystemd.git strbuf: several cleanups - use FOREACH_ARRAY(), - add one missing assertion, - reduce indentation. --- 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 */