Re: [PATCH 6/9] Rewrite launch_editor, create_tag and stripspace to use strbufs.
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Sep 6, 2007, 16:38 UTC
- Message-ID
- <Pine.LNX.4.64.0709061732480.28586@racer.site>
- In-Reply-To
- <1189038225525-git-send-email-krh@redhat.com>
Hi,
On Wed, 5 Sep 2007, Kristian Høgsberg wrote:
Show 52 quoted lines
> diff --git a/strbuf.c b/strbuf.c
> index fcfc05e..ed2afea 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -73,43 +74,15 @@ void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
> {
> char buffer[2048];
> va_list args;
> - int len, size = 2 * sizeof buffer;
> + int len;
>
> va_start(args, fmt);
> len = vsnprintf(buffer, sizeof(buffer), fmt, args);
> va_end(args);
>
> - if (len > sizeof(buffer)) {
> - /*
> - * Didn't fit in the buffer, but this vsnprintf at
> - * least gives us the required length back. Grow the
> - * buffer acccordingly and try again.
> - */
> - strbuf_grow(sb, len);
> - va_start(args, fmt);
> - len = vsnprintf(sb->buf + sb->len,
> - sb->alloc - sb->len, fmt, args);
> - va_end(args);
> - } else if (len >= 0) {
> - /*
> - * The initial vsnprintf fit in the temp buffer, just
> - * copy it to the strbuf.
> - */
> - strbuf_add(sb, buffer, len);
> - } else {
> - /*
> - * This vnsprintf sucks and just returns -1 when the
> - * buffer is too small. Keep doubling the size until
> - * it fits.
> - */
> - while (len < 0) {
> - strbuf_grow(sb, size);
> - va_start(args, fmt);
> - len = vsnprintf(sb->buf + sb->len,
> - sb->alloc - sb->len, fmt, args);
> - va_end(args);
> - size *= 2;
> - }
> - }
> + if (len > sizeof(buffer) || len < 0)
> + die("out of buffer space\n");
> +
> + strbuf_add(sb, buffer, len);
> }Really?
(If you find the time, it would be really nice to rebase that patch series on top of Pierre's strbuf work...)
Ciao, Dscho