summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 902f235)
raw | patch | inline | side by side (parent: 902f235)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 12 Jan 2010 20:09:54 +0000 (12:09 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 13 Jan 2010 20:12:52 +0000 (12:12 -0800) |
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>
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>
strbuf.h | patch | blob | history |
diff --git a/strbuf.h b/strbuf.h
index fa07ecf094bd3ef8997958fde29199f8fb6421b9..4971743a246950333fba455770937075e5a4eece 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
strbuf_add(sb, s, strlen(s));
}
static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) {
+ strbuf_grow(sb, sb2->len);
strbuf_add(sb, sb2->buf, sb2->len);
}
extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);