summaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/strbuf.h b/strbuf.h
index 567e2d1..3b19de3 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -65,14 +65,17 @@ static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) {
static inline size_t strbuf_avail(struct strbuf *sb) {
return sb->alloc ? sb->alloc - sb->len - 1 : 0;
}
+
+extern void strbuf_grow(struct strbuf *, size_t);
+
static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
- assert (len < sb->alloc);
+ if (!sb->alloc)
+ strbuf_grow(sb, 0);
+ assert(len < sb->alloc);
sb->len = len;
sb->buf[len] = '\0';
}
-extern void strbuf_grow(struct strbuf *, size_t);
-
/*----- content related -----*/
extern void strbuf_rtrim(struct strbuf *);