Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit d4c44443b665ee8e6bd638b5c1b3fa6aa2a1226c 1 parent eba1351
gerberb authored June 08, 2008 gitster committed June 08, 2008

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

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

0 notes on commit d4c4444

Please sign in to comment.
Something went wrong with that request. Please try again.