use strbuf_addstr() for adding constant strings to a strbuf, part 2
Replace uses of strbuf_addf() for adding strings with more lightweight strbuf_addstr() calls. This makes the intent clearer and avoids potential issues with printf format specifiers. 02962d36845b89145cd69f8bc65e015d78ae3434 already converted six cases, this patch covers eleven more. A semantic patch for Coccinelle is included for easier checking for new cases that might be introduced in the future. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 15, 2016 at 20:31 UTC
a22ae753cb297cb8a1e3ae950ae4415190cd51d5
7 files changed
+18
-12
builtin/fmt-merge-msg.c
+1
-1
@@ -395,7 +395,7 @@ static void shortlog(const char *name,
395
396
for (i = 0; i < subjects.nr; i++)
397
if (i >= limit)
398
- strbuf_addf(out, " ...\n");
398
+ strbuf_addstr(out, " ...\n");
399
else
400
strbuf_addf(out, " %s\n", subjects.items[i].string);
401
builtin/merge.c
+1
-1
@@ -940,7 +940,7 @@ static void write_merge_state(struct commit_list *remoteheads)
940
941
strbuf_reset(&buf);
942
if (fast_forward == FF_NO)
943
- strbuf_addf(&buf, "no-ff");
943
+ strbuf_addstr(&buf, "no-ff");
944
write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
945
}
946
builtin/submodule--helper.c
+3
-2
@@ -749,8 +749,9 @@ static int update_clone_get_next_task(struct child_process *child,
749
ce = suc->failed_clones[index];
750
if (!prepare_to_clone_next_submodule(ce, child, suc, err)) {
751
suc->current ++;
752
- strbuf_addf(err, "BUG: submodule considered for cloning,"
753
- "doesn't need cloning any more?\n");
752
+ strbuf_addstr(err, "BUG: submodule considered for "
753
+ "cloning, doesn't need cloning "
754
+ "any more?\n");
755
return 0;
756
}
757
p = xmalloc(sizeof(*p));
contrib/coccinelle/strbuf.cocci
new
+5
@@ -0,0 +1,5 @@
1
+@@
2
+expression E1, E2;
3
+@@
4
+- strbuf_addf(E1, E2);
5
++ strbuf_addstr(E1, E2);
merge-recursive.c
+1
-1
@@ -206,7 +206,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
206
find_unique_abbrev(commit->object.oid.hash,
207
DEFAULT_ABBREV));
208
if (parse_commit(commit) != 0)
209
- strbuf_addf(&o->obuf, _("(bad commit)\n"));
209
+ strbuf_addstr(&o->obuf, _("(bad commit)\n"));
210
else {
211
const char *title;
212
const char *msg = get_commit_buffer(commit, NULL);
remote.c
+4
-4
@@ -2073,7 +2073,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
2073
_("Your branch is based on '%s', but the upstream is gone.\n"),
2074
base);
2075
if (advice_status_hints)
2076
- strbuf_addf(sb,
2076
+ strbuf_addstr(sb,
2077
_(" (use \"git branch --unset-upstream\" to fixup)\n"));
2078
} else if (!ours && !theirs) {
2079
strbuf_addf(sb,
@@ -2086,7 +2086,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
2086
ours),
2087
base, ours);
2088
if (advice_status_hints)
2089
- strbuf_addf(sb,
2089
+ strbuf_addstr(sb,
2090
_(" (use \"git push\" to publish your local commits)\n"));
2091
} else if (!ours) {
2092
strbuf_addf(sb,
@@ -2097,7 +2097,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
2097
theirs),
2098
base, theirs);
2099
if (advice_status_hints)
2100
- strbuf_addf(sb,
2100
+ strbuf_addstr(sb,
2101
_(" (use \"git pull\" to update your local branch)\n"));
2102
} else {
2103
strbuf_addf(sb,
@@ -2110,7 +2110,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
2110
ours + theirs),
2111
base, ours, theirs);
2112
if (advice_status_hints)
2113
- strbuf_addf(sb,
2113
+ strbuf_addstr(sb,
2114
_(" (use \"git pull\" to merge the remote branch into yours)\n"));
2115
}
2116
free(base);
wt-status.c
+3
-3
@@ -367,11 +367,11 @@ static void wt_status_print_change_data(struct wt_status *s,
367
if (d->new_submodule_commits || d->dirty_submodule) {
368
strbuf_addstr(&extra, " (");
369
if (d->new_submodule_commits)
370
- strbuf_addf(&extra, _("new commits, "));
370
+ strbuf_addstr(&extra, _("new commits, "));
371
if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
372
- strbuf_addf(&extra, _("modified content, "));
372
+ strbuf_addstr(&extra, _("modified content, "));
373
if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
374
- strbuf_addf(&extra, _("untracked content, "));
374
+ strbuf_addstr(&extra, _("untracked content, "));
375
strbuf_setlen(&extra, extra.len - 2);
376
strbuf_addch(&extra, ')');
377
}