X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=strbuf.c;h=5efcfc8860a82766b53a0d579fbdd0844d0f9b62;hb=1b56bc9a1545902db64b8bdce48a499900acfe0b;hp=dbd8c4bcfb2f8549b8713a8d9fbbfd8adcd0088c;hpb=91db267ec849279053cf3ac3066c2f2c11db4321;p=git.git diff --git a/strbuf.c b/strbuf.c index dbd8c4bcf..5efcfc886 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,5 +1,14 @@ #include "cache.h" +int prefixcmp(const char *str, const char *prefix) +{ + for (; ; str++, prefix++) + if (!*prefix) + return 0; + else if (*str != *prefix) + return (unsigned char)*prefix - (unsigned char)*str; +} + /* * Used as the default ->buf value, so that people can always assume * buf is non NULL and ->buf is NUL terminated even for a freshly @@ -118,12 +127,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);