strbuf: always return a non-NULL value from strbuf_detach
[gitweb.git] / strbuf.c
index 5135d5950d9a5ea3ce8064e5491e53da17645da9..5427cfdc658e47b930603d64dd75461a686bdf7d 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -44,7 +44,9 @@ void strbuf_release(struct strbuf *sb)
 
 char *strbuf_detach(struct strbuf *sb, size_t *sz)
 {
-       char *res = sb->alloc ? sb->buf : NULL;
+       char *res;
+       strbuf_grow(sb, 0);
+       res = sb->buf;
        if (sz)
                *sz = sb->len;
        strbuf_init(sb, 0);