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

[RFC] coccinelle: detect struct strbuf passed by value

From
Deveshi Dwivedi <deveshigurgaon@gmail.com>
Date
Mar 14, 2026, 17:12 UTC
Message-ID
<CAG7UgESKLMnO_4+PSJUt-TXJxFQyxEEfpCmJfMmTw2+rhT-HWw@mail.gmail.com>

While reviewing the write_worktree_linking_files() fix [1], Jeff King suggested adding a coccinelle rule to catch functions that take struct strbuf by value. He noted that a reporting rule using coccinelle's Python scripting extensions could emit a descriptive warning.

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
      ,...)
      {
      ...
      }

Running 'make coccicheck COCCI=contrib/coccinelle/strbuf.cocci' on master catches two instances:

  - write_worktree_linking_files() in worktree.c, which is already
    fixed by the series in [1].
  - save_untracked_files() in builtin/stash.c, which takes
    'struct strbuf files' by value.  This is the same class of bug.

Sending this as an RFC to get feedback on whether this rule would be a reasonable addition before preparing a patch.

[1] https://lore.kernel.org/git/20260309192600.GC309867@coredump.intra.peff.net/
Deveshi Dwivedi
Next: Jeff King
Message 1 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.