]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/strbuf.c
Merge pull request #2709 from vcaputo/normalize_inc_dec_usage
[thirdparty/systemd.git] / src / basic / strbuf.c
index 01a076c2baf204e50f170bbcd2fbca44ed527f76..797f00cf7165f52485d659f2f80c23eaa49c6e4c 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "util.h"
+#include "alloc-util.h"
 #include "strbuf.h"
 
 /*
@@ -122,7 +121,7 @@ static void bubbleinsert(struct strbuf_node *node,
                 sizeof(struct strbuf_child_entry) * (node->children_count - left));
         node->children[left] = new;
 
-        node->children_count ++;
+        node->children_count++;
 }
 
 /* add string, return the index/offset into the buffer */
@@ -157,6 +156,10 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
                         return off;
                 }
 
+                /* bsearch is not allowed on a NULL sequence */
+                if (node->children_count == 0)
+                        break;
+
                 /* lookup child node */
                 c = s[len - 1 - depth];
                 search.c = c;