Skip to content

Commit 253ddb6

Browse files
committed
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
2 parents c006399 + 8f8e1b0 commit 253ddb6

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

builtin/stash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ static int check_changes(const struct pathspec *ps, int include_untracked,
12321232
}
12331233

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

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

15021502
if (include_untracked) {
1503-
if (save_untracked_files(info, &msg, untracked_files)) {
1503+
if (save_untracked_files(info, &msg, &untracked_files)) {
15041504
if (!quiet)
15051505
fprintf_ln(stderr, _("Cannot save "
15061506
"the untracked files"));

contrib/coccinelle/strbuf.cocci

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,14 @@ expression E1, E2;
6060
@@
6161
- strbuf_addstr(E1, real_path(E2));
6262
+ strbuf_add_real_path(E1, E2);
63+
64+
@@
65+
identifier fn, param;
66+
@@
67+
fn(...,
68+
- struct strbuf param
69+
+ struct strbuf *param
70+
,...)
71+
{
72+
...
73+
}

0 commit comments

Comments
 (0)