diff options
Diffstat (limited to 'src/basic/strbuf.c')
-rw-r--r-- | src/basic/strbuf.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index 01a076c2ba..4bef87d3c2 100644 --- a/src/basic/strbuf.c +++ b/src/basic/strbuf.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -19,10 +17,11 @@ 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,8 +156,13 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) { return off; } - /* lookup child node */ c = s[len - 1 - depth]; + + /* bsearch is not allowed on a NULL sequence */ + if (node->children_count == 0) + break; + + /* lookup child node */ search.c = c; child = bsearch(&search, node->children, node->children_count, sizeof(struct strbuf_child_entry), |