]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strbuf: several cleanups
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Jun 2024 15:20:26 +0000 (00:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 17 Jun 2024 15:26:15 +0000 (00:26 +0900)
- use FOREACH_ARRAY(),
- add one missing assertion,
- reduce indentation.

src/basic/strbuf.c

index c08aa82e54f2257ff6dcd88f9bad490023cb9ca3..e12c0f9b1133ed5501a8285bafc121cced25134c 100644 (file)
@@ -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 */