Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-01-12 23:09:54 +0300
committerJunio C Hamano <gitster@pobox.com>2010-01-13 23:12:52 +0300
commit81d2caefedefa40557baf7af846580f35de3f995 (patch)
tree983d8109d02eaf781cab0c8cf6b69e270b5b2067 /strbuf.h
parent902f235378cb2b2f6dd5dd664b9630c95321f0ae (diff)
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>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index fa07ecf094..4971743a24 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -105,6 +105,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
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);