@matheusbsbs / matheus-bagliano / commits / d4c44443b6
Fork 0

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>

Boyd Lynn Gerber committed Jun 8, 2008 at 09:26 UTC d4c44443b665ee8e6bd638b5c1b3fa6aa2a1226c
1 file changed +8 -3
progress.c
+8 -3
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
241 *p_progress = NULL;
242 if (progress->last_value != -1) {
243 /* Force the last update */
244 - char buf[strlen(msg) + 5];
244 + char buf[128], *bufp;
245 + size_t len = strlen(msg) + 5;
246 struct throughput *tp = progress->throughput;
247 +
248 + bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
249 if (tp) {
250 unsigned int rate = !tp->avg_misecs ? 0 :
251 tp->avg_bytes / tp->avg_misecs;
252 throughput_string(tp, tp->curr_total, rate);
253 }
254 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);
259 }
260 clear_progress_signal();
261 free(progress->throughput);