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

Re: Use of strbuf.buf when strbuf.len == 0

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Sep 29, 2007, 00:51 UTC
Message-ID
<alpine.LFD.0.999.0709281746500.3579@woody.linux-foundation.org>
In-Reply-To
<20070927101300.GD10289@artemis.corp>
On Thu, 27 Sep 2007, Pierre Habouzit wrote:
Show 6 quoted lines
> 
>   I can see a way, that would need special proof-reading of the strbuf
> module, but should not harm its users, that would be to change
> STRBUF_INIT to work this way:
> 
>   { .buf = "", .len = 0, .alloc = 0 }
I'd like to pipe up a bit here..

I think the above is a good fix for the current problem of wanting to always be able to use "sb->buf", but I thinkit actually has the potential to fix another issue entirely.

Namely strbuf's that are initialized from various static strings and/or strings not directly allocated with malloc().

That's not necessarily something really unusual. Wanting to initialize a string with a fixed constant value is a common problem.

And wouldn't it be nice if you could actually do that, with
	{ .buf = "static initializer", .len = 18, .alloc = 0 }

and have all the strbuf routines that modify the initializer (including making it shorter!) notice that the allocation is too short, and create a new allocation?

Hmm?
			Linus
Previous: Pierre HabouzitNext: Pierre Habouzit
Message 5 of 10 in “Use of strbuf.buf when strbuf.len == 0”
  1. Junio C HamanoSep 27, 2007
  2. Pierre HabouzitSep 27, 2007
  3. 1/2 double free in builtin-update-index.cPierre Habouzit, Sep 27, 2007
  4. 2/2 strbuf change: be sure ->buf is never ever NULL.Pierre Habouzit, Sep 27, 2007
  5. Linus TorvaldsSep 29, 2007
  6. Pierre HabouzitSep 29, 2007
  7. Pierre HabouzitSep 27, 2007
  8. 1/1 Make read_patch_file work on a strbuf.Pierre Habouzit, Sep 27, 2007
  9. 1/1 Make read_patch_file work on a strbuf.Pierre Habouzit, Sep 27, 2007
  10. Pierre HabouzitSep 27, 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.