aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-11-13 03:22:44 -0500
committerJunio C Hamano <gitster@pobox.com>2007-11-14 02:00:13 -0800
commitf141bd804d2cba4500769934f9d9e7f0f7bcf282 (patch)
treebb94f1d18a897f79d5515661ed5b0b2404a242f0 /strbuf.c
parent71aa2b8f0ee7cb2e60871f327996af21af88a668 (diff)
downloadgit-f141bd804d2cba4500769934f9d9e7f0f7bcf282.tar.gz
git-f141bd804d2cba4500769934f9d9e7f0f7bcf282.tar.xz
Handle broken vsnprintf implementations in strbuf
Solaris 9's vsnprintf implementation returns -1 if we pass it a buffer of length 0. The only way to get it to give us the actual length necessary for the formatted string is to grow the buffer out to have at least 1 byte available in the strbuf and then ask it to compute the length. If the available space is 0 I'm growing it out by 64 to ensure we will get an accurate length estimate from all implementations. Some callers may need to grow the strbuf again but 64 should be a reasonable enough initial growth. We also no longer silently fail to append to the string when we are faced with a broken vsnprintf implementation. On Solaris 9 this silent failure caused me to no longer be able to execute "git clone" as we tried to exec the empty string rather than "git-clone". Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/strbuf.c b/strbuf.c
index f4201e160..cbada946c 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -111,12 +111,13 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
int len;
va_list ap;
+ if (!strbuf_avail(sb))
+ strbuf_grow(sb, 64);
va_start(ap, fmt);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
va_end(ap);
- if (len < 0) {
- len = 0;
- }
+ if (len < 0)
+ die("your vsnprintf is broken");
if (len > strbuf_avail(sb)) {
strbuf_grow(sb, len);
va_start(ap, fmt);