git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/9] Rewrite launch_editor, create_tag and stripspace to use strbufs.

From
Kristian Høgsberg <krh@redhat.com>
Date
Sep 17, 2007, 22:59 UTC
Message-ID
<1190069981.10112.12.camel@hinata.boston.redhat.com>
In-Reply-To
<Pine.LNX.4.64.0709061732480.28586@racer.site>
On Thu, 2007-09-06 at 17:38 +0100, Johannes Schindelin wrote:
Show 61 quoted lines
> Hi,
> 
> On Wed, 5 Sep 2007, Kristian Høgsberg wrote:
> 
> > 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...)

Argh, this was a screwup when I edited the patch series. The next series is based on Pierres changes.

Kristian
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 17 of 25 in “Enable wt-status output to a given FILE pointer.”
  1. 1/9 Enable wt-status output to a given FILE pointer.Kristian Høgsberg, Sep 6, 2007
  2. 2/9 Enable wt-status to run against non-standard index file.Kristian Høgsberg, Sep 6, 2007
  3. 3/9 Add strbuf_printf() to do formatted printing to a strbuf.Kristian Høgsberg, Sep 6, 2007
  4. 4/9 Introduce entry point for launching add--interactive.Kristian Høgsberg, Sep 6, 2007
  5. 5/9 Introduce strbuf_read_fd().Kristian Høgsberg, Sep 6, 2007
  6. 6/9 Rewrite launch_editor, create_tag and stripspace to use strbufs.Kristian Høgsberg, Sep 6, 2007
  7. 7/9 Add strbuf_read_path().Kristian Høgsberg, Sep 6, 2007
  8. 8/9 Export rerere() and launch_editor().Kristian Høgsberg, Sep 6, 2007
  9. 9/9 Implement git commit as a builtin command.Kristian Høgsberg, Sep 6, 2007
  10. Johannes SchindelinSep 6, 2007
  11. Kristian HøgsbergSep 17, 2007
  12. Johannes SchindelinSep 17, 2007
  13. Jeff KingSep 17, 2007
  14. Kristian HøgsbergSep 18, 2007
  15. Johannes SchindelinSep 6, 2007
  16. Johannes SchindelinSep 6, 2007
  17. Kristian HøgsbergSep 17, 2007
  18. Johannes SchindelinSep 6, 2007
  19. Kristian HøgsbergSep 17, 2007
  20. Johannes SchindelinSep 17, 2007
  21. Junio C HamanoSep 6, 2007
  22. Pierre HabouzitSep 6, 2007
  23. Pierre HabouzitSep 6, 2007
  24. Johannes SchindelinSep 6, 2007
  25. Kristian HøgsbergSep 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.