Skip to content

Commit

Permalink
strbuf_addbuf(): allow passing the same buf to dst and src
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 13, 2010
1 parent 902f235 commit 81d2cae
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 81d2cae

Please sign in to comment.