Skip to content

Commit f989ac2

Browse files
committed
Merge branch 'mm/two-more-xstrfmt' into maint
Code clean-up and a string truncation fix. * mm/two-more-xstrfmt: bisect_next_all: convert xsnprintf to xstrfmt stop_progress_msg: convert xsnprintf to xstrfmt
2 parents 3d0449d + 2cfa835 commit f989ac2

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

bisect.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
940940
struct commit_list *tried;
941941
int reaches = 0, all = 0, nr, steps;
942942
const unsigned char *bisect_rev;
943-
char steps_msg[32];
943+
char *steps_msg;
944944

945945
read_bisect_terms(&term_bad, &term_good);
946946
if (read_bisect_refs())
@@ -990,14 +990,15 @@ int bisect_next_all(const char *prefix, int no_checkout)
990990

991991
nr = all - reaches - 1;
992992
steps = estimate_bisect_steps(all);
993-
xsnprintf(steps_msg, sizeof(steps_msg),
994-
Q_("(roughly %d step)", "(roughly %d steps)", steps),
995-
steps);
993+
994+
steps_msg = xstrfmt(Q_("(roughly %d step)", "(roughly %d steps)",
995+
steps), steps);
996996
/* TRANSLATORS: the last %s will be replaced with
997997
"(roughly %d steps)" translation */
998998
printf(Q_("Bisecting: %d revision left to test after this %s\n",
999999
"Bisecting: %d revisions left to test after this %s\n",
10001000
nr), nr, steps_msg);
1001+
free(steps_msg);
10011002

10021003
return bisect_checkout(bisect_rev, no_checkout);
10031004
}

progress.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,18 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
243243
*p_progress = NULL;
244244
if (progress->last_value != -1) {
245245
/* Force the last update */
246-
char buf[128], *bufp;
247-
size_t len = strlen(msg) + 5;
246+
char *buf;
248247
struct throughput *tp = progress->throughput;
249248

250-
bufp = (len < sizeof(buf)) ? buf : xmallocz(len);
251249
if (tp) {
252250
unsigned int rate = !tp->avg_misecs ? 0 :
253251
tp->avg_bytes / tp->avg_misecs;
254252
throughput_string(&tp->display, tp->curr_total, rate);
255253
}
256254
progress_update = 1;
257-
xsnprintf(bufp, len + 1, ", %s.\n", msg);
258-
display(progress, progress->last_value, bufp);
259-
if (buf != bufp)
260-
free(bufp);
255+
buf = xstrfmt(", %s.\n", msg);
256+
display(progress, progress->last_value, buf);
257+
free(buf);
261258
}
262259
clear_progress_signal();
263260
if (progress->throughput)

0 commit comments

Comments
 (0)