On Tue, Apr 26, 2011 at 07:24:20PM +0700, Nguyán ThÃi Ngác Duy wrote: > static inline void strbuf_setlen(struct strbuf *sb, size_t len) { > if (!sb->alloc) > - strbuf_grow(sb, 0); > + strbuf_grow(sb, len); > assert(len < sb->alloc); > sb->len = len; > sb->buf[len] = '\0'; This should be better. But I fail to see why it corrupts memory :( @@ -33,9 +33,8 @@ static inline size_t strbuf_avail(const struct strbuf *sb) { extern void strbuf_grow(struct strbuf *, size_t); static inline void strbuf_setlen(struct strbuf *sb, size_t len) { - if (!sb->alloc) - strbuf_grow(sb, 0); - assert(len < sb->alloc); + if (sb->alloc < len + 1) + strbuf_grow(sb, len - sb->alloc); sb->len = len; sb->buf[len] = '\0'; } -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html