Skip to content

Commit d4c4444

Browse files
gerberbgitster
authored andcommitted
progress.c: avoid use of dynamic-sized array
Dynamically sized arrays are gcc and C99 construct. Using them hurts portability to older compilers, although using them is nice in this case it is not desirable. This patch removes the only use of the construct in stop_progress_msg(); the function is about writing out a single line of a message, and the existing callers of this function feed messages of only bounded size anyway, so use of dynamic array is simply overkill. Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent eba1351 commit d4c4444

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

progress.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
241241
*p_progress = NULL;
242242
if (progress->last_value != -1) {
243243
/* Force the last update */
244-
char buf[strlen(msg) + 5];
244+
char buf[128], *bufp;
245+
size_t len = strlen(msg) + 5;
245246
struct throughput *tp = progress->throughput;
247+
248+
bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
246249
if (tp) {
247250
unsigned int rate = !tp->avg_misecs ? 0 :
248251
tp->avg_bytes / tp->avg_misecs;
249252
throughput_string(tp, tp->curr_total, rate);
250253
}
251254
progress_update = 1;
252-
sprintf(buf, ", %s.\n", msg);
253-
display(progress, progress->last_value, buf);
255+
sprintf(bufp, ", %s.\n", msg);
256+
display(progress, progress->last_value, bufp);
257+
if (buf != bufp)
258+
free(bufp);
254259
}
255260
clear_progress_signal();
256261
free(progress->throughput);

0 commit comments

Comments
 (0)