diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-03-24 12:31:34 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-24 12:31:34 -0700 |
| commit | 253ddb6016077a86b86bedebb40635d81b5ab8e9 (patch) | |
| tree | 20290957c17839f52204274dc55e96d13ee4a36b | |
| parent | c006399b738ed602a67e6077403376a79c94bbe4 (diff) | |
| parent | 8f8e1b080701d4b02ca3732eed2706b1a5328c5d (diff) | |
| download | git-253ddb6016077a86b86bedebb40635d81b5ab8e9.tar.xz | |
Merge branch 'dd/cocci-do-not-pass-strbuf-by-value'
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
| -rw-r--r-- | builtin/stash.c | 6 | ||||
| -rw-r--r-- | contrib/coccinelle/strbuf.cocci | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/builtin/stash.c b/builtin/stash.c index 7c68a1d7f9..95c5005b0b 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -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")); diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 5f06105df6..83bd93be5f 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -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 + ,...) + { + ... + } |
