Merge branch 'dd/cocci-do-not-pass-strbuf-by-value' into next

Add a coccinelle rule to break the build when "struct strbuf" gets
passed by value.

* dd/cocci-do-not-pass-strbuf-by-value:
  stash: do not pass strbuf by value
  coccinelle: detect struct strbuf passed by value
next
Junio C Hamano 2026-03-18 12:23:44 -07:00
commit a2ffed1127
2 changed files with 14 additions and 3 deletions

View File

@ -1232,7 +1232,7 @@ static int check_changes(const struct pathspec *ps, int include_untracked,
}

static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
struct strbuf files)
struct strbuf *files)
{
int ret = 0;
struct strbuf untracked_msg = STRBUF_INIT;
@ -1246,7 +1246,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
stash_index_path.buf);

strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf);
if (pipe_command(&cp_upd_index, files.buf, files.len, NULL, 0,
if (pipe_command(&cp_upd_index, files->buf, files->len, NULL, 0,
NULL, 0)) {
ret = -1;
goto done;
@ -1500,7 +1500,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
parents = NULL;

if (include_untracked) {
if (save_untracked_files(info, &msg, untracked_files)) {
if (save_untracked_files(info, &msg, &untracked_files)) {
if (!quiet)
fprintf_ln(stderr, _("Cannot save "
"the untracked files"));

View File

@ -60,3 +60,14 @@ expression E1, E2;
@@
- strbuf_addstr(E1, real_path(E2));
+ strbuf_add_real_path(E1, E2);

@@
identifier fn, param;
@@
fn(...,
- struct strbuf param
+ struct strbuf *param
,...)
{
...
}