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

Re: [RFC] cocci: .buf in a strbuf object can never be NULL

From
Jeff King <peff@peff.net>
Date
Mar 21, 2026, 16:39 UTC
Message-ID
<20260321163941.GA717067@coredump.intra.peff.net>
In-Reply-To
<xmqqqzpdb172.fsf@gitster.g>
On Sat, Mar 21, 2026 at 09:24:17AM -0700, Junio C Hamano wrote:
Show 8 quoted lines
> Here is my second try.  strbuf_getwholeline() does not have to break
> strbuf invariants even tentatively.  We just grab the guts of sb,
> let getdelim() possibly reallocate, and then return it in the normal
> case.
> 
> In the EOF code path, the only special thing we need is when we
> started with slopbuf[] and getdelim() allocated some bytes yet
> returned EOF.  We are expected to free it before returning.

This is similar to what I initially wrote (but revised before sending), but I don't think it works because...

> +	/* 
> +	 * We haven't touched sb at all; as with the initial "were we
> +	 * already at EOF?" case, return EOF without touching sb.
>  	 */

...this part isn't necessarily true. We handed sb->buf (copied via the local "buf") to getdelim(). It might have reallocated it behind our backs and returned the new pointer, and now sb->buf is dangling.

And in that sense, assigning sb->buf to a local buf becomes _more_ confusing, because now we have two copies of a pointer that is being mutated.

Show 6 quoted lines
> By the way, the big comment about xrealloc() in the middle, most of
> which is outside the post-context of the first hunk, should be
> updated, as our xrealloc() do not aggressively try to recover these
> days, if I understand correctly.  I left it outside the scope of
> this patch, whose sole focus is to reduce the number of places in
> the codebase that check if sb->buf is NULL.
Yes, I think you're right.
-Peff
Previous: Junio C Hamano
Message 20 of 20 in “rerere: update to modern representation of empty strbufs”
  1. rerere: update to modern representation of empty strbufsJunio C Hamano, Mar 19, 2026
  2. Patrick SteinhardtMar 19, 2026
  3. [RFC] cocci: .buf in a strbuf object can never be NULLJunio C Hamano, Mar 19, 2026
  4. Jeff KingMar 19, 2026
  5. Junio C HamanoMar 20, 2026
  6. Jeff KingMar 20, 2026
  7. Junio C HamanoMar 20, 2026
  8. Jeff KingMar 20, 2026
  9. Junio C HamanoMar 20, 2026
  10. Jeff KingMar 20, 2026
  11. René ScharfeMar 21, 2026
  12. Jeff KingMar 21, 2026
  13. René ScharfeMar 21, 2026
  14. Jeff KingMar 21, 2026
  15. René ScharfeMar 21, 2026
  16. Jeff KingMar 22, 2026
  17. Junio C HamanoMar 22, 2026
  18. Jeff KingMar 22, 2026
  19. Junio C HamanoMar 21, 2026
  20. Jeff KingMar 21, 2026

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.