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

Re: [RFC] coccinelle: detect struct strbuf passed by value

From
Jeff King <peff@peff.net>
Date
Mar 15, 2026, 02:55 UTC
Message-ID
<20260315025508.GA926820@coredump.intra.peff.net>
In-Reply-To
<CAG7UgESKLMnO_4+PSJUt-TXJxFQyxEEfpCmJfMmTw2+rhT-HWw@mail.gmail.com>
On Sat, Mar 14, 2026 at 10:42:19PM +0530, Deveshi Dwivedi wrote:
Show 20 quoted lines
> A transformation rule achieves the same detection without the
> dependency.  It rewrites a by-value strbuf parameter to a pointer.
> The resulting diff will not produce compilable code on its own
> (callers and the function body still need updating), but the spatch
> output alerts the developer that the signature needs attention.
> This is consistent with the other rules in strbuf.cocci, which also
> rewrite to the preferred form.
> 
> The rule itself:
> 
>     @@
>     identifier fn, param;
>     @@
>       fn(...,
>     - struct strbuf param
>     + struct strbuf *param
>       ,...)
>       {
>       ...
>       }

This is much better than what I posted before. The real source of the problem is the functions which take strbufs by value, not the callsites that pass it to them (and mine was checking the latter).

And your use of "..." is better than what I had. I think mine insisted on having arguments after the strbuf, which is why it failed to find the case in save_untracked_files().

So the only question to me is whether people who hit the coccinelle suggestion might be confused by the patch output, since it doesn't carry any rationale. But I would rather catch the problem and risk confusion then have it go unnoticed.

-Peff
Previous: Deveshi DwivediNext: Deveshi Dwivedi
Message 2 of 3 in “[RFC] coccinelle: detect struct strbuf passed by value”
  1. Deveshi DwivediMar 14, 2026
  2. Jeff KingMar 15, 2026
  3. Deveshi DwivediMar 15, 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.