On Sun, Sep 09, 2007 at 10:24:04PM +0000, Junio C Hamano wrote: > Pierre Habouzit <madcoder@xxxxxxxxxx> writes: > > > +void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) { > > + strbuf_grow(sb, len); > > + if (pos >= sb->len) { > > + sb->len = pos; > > + } else { > > + memmove(sb->buf + pos + len, sb->buf + pos, sb->len - pos); > > + } > > + memcpy(sb->buf + pos, data, len); > > + strbuf_setlen(sb, sb->len + len); > > +} > > + > > What's the semantics of inserting way beyond len? If the buf is > 5-byte "ABCDE" currently and you insert "FG" at position 7, do > you get "ABCDE" + 2-byte undefined garbage + "FG" and result in > 9-byte buffer? Or "FG" is appended after position 5 and you get > "ABCDEFG" 7-byte buffer? > > I personally think we should OOPS such a caller, but I suspect > you wanted the latter, in which case I think "sb->len = pos" > assignment is done in the wrong direction, in other words, it > should read "pos = sb->len" instead. Yes, this was spotted by someone already. The semantics I attach is that if pos is >= sb->len it appends (like it's commented in the .h). Another patch I sent fixes that. -- ·O· Pierre Habouzit ··O madcoder@xxxxxxxxxx OOO http://www.madism.org
Attachment:
pgp62Cu3PqSVg.pgp
Description: PGP signature