strbuf_addbuf(): allow passing the same buf to dst and src
If sb and sb2 are the same (i.e. doubling the string), the underlying strbuf_add() can make sb2->buf invalid by calling strbuf_grow(sb) at the beginning; if realloc(3) done by strbuf_grow() needs to move the string, strbuf_add() will read from an already freed buffer. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 12, 2010 at 12:09 UTC
81d2caefedefa40557baf7af846580f35de3f995
1 file changed
+1
strbuf.h
+1
@@ -105,6 +105,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
105
strbuf_add(sb, s, strlen(s));
106
}
107
static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) {
108
+ strbuf_grow(sb, sb2->len);
109
strbuf_add(sb, sb2->buf, sb2->len);
110
}
111
extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);