summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a33bcb)
raw | patch | inline | side by side (parent: 7a33bcb)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 26 Sep 2007 09:26:06 +0000 (02:26 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 26 Sep 2007 09:27:05 +0000 (02:27 -0700) |
strbuf_setlen() expect to be able to NUL terminate the buffer,
but a completely empty strbuf could have an empty buffer with 0
allocation; both the assert() and the assignment for NUL
termination would fail.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
but a completely empty strbuf could have an empty buffer with 0
allocation; both the assert() and the assignment for NUL
termination would fail.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.h | patch | blob | history |
diff --git a/strbuf.h b/strbuf.h
index 567e2d17d1a5300b35b010c73ed68a376c6001cb..3b19de3048bf9d96feb11380e743db2034acad50 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
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 *);