summaryrefslogtreecommitdiff
path: root/src/libbasic/strbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libbasic/strbuf.c')
-rw-r--r--src/libbasic/strbuf.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libbasic/strbuf.c b/src/libbasic/strbuf.c
index 77220c0251..4bef87d3c2 100644
--- a/src/libbasic/strbuf.c
+++ b/src/libbasic/strbuf.c
@@ -121,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 */
@@ -156,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),