git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] strbuf: allocate enough space when strbuf_setlen() is called first time
@ 2011-04-26 12:24 Nguyễn Thái Ngọc Duy
  2011-04-26 15:09 ` Nguyen Thai Ngoc Duy
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-04-26 12:24 UTC (permalink / raw)
  To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy

strbuf_grow(sb, 0) may allocate less than requested len and violate the
next assertion.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 strbuf.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/strbuf.h b/strbuf.h
index 07060ce..ab213da 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -34,7 +34,7 @@ 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);
+		strbuf_grow(sb, len);
 	assert(len < sb->alloc);
 	sb->len = len;
 	sb->buf[len] = '\0';
-- 
1.7.4.74.g639db

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-04-28 16:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26 12:24 [PATCH] strbuf: allocate enough space when strbuf_setlen() is called first time Nguyễn Thái Ngọc Duy
2011-04-26 15:09 ` Nguyen Thai Ngoc Duy
2011-04-26 15:25 ` Junio C Hamano
2011-04-26 15:32   ` Nguyen Thai Ngoc Duy
2011-04-26 16:54     ` René Scharfe
2011-04-26 17:18 ` Junio C Hamano
2011-04-26 21:26   ` René Scharfe
2011-04-26 21:51     ` Junio C Hamano
2011-04-27 17:24       ` René Scharfe
2011-04-28 16:57         ` Junio C Hamano
2011-04-27  0:12     ` Nguyen Thai Ngoc Duy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).