git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Boyd Lynn Gerber <gerberb@zenez.com>
Cc: Thomas Harning <harningt@gmail.com>,
	Jeremy Maitin-Shepard <jbms@cmu.edu>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH] This patch is to allow 12 different OS's to compile and run git.
Date: Fri, 06 Jun 2008 16:08:15 -0700	[thread overview]
Message-ID: <7vmylyrwkg.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: Pine.LNX.4.64.0806061359080.18454@xenau.zenez.com

Boyd Lynn Gerber <gerberb@zenez.com> writes:

> diff --git a/progress.c b/progress.c
> index d19f80c..295c4e3 100644
> --- a/progress.c
> +++ b/progress.c
> @@ -241,7 +241,8 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
>  	*p_progress = NULL;
>  	if (progress->last_value != -1) {
>  		/* Force the last update */
> -		char buf[strlen(msg) + 5];
> +		/* char buf[strlen(msg) + 5]; */
> +		char *buf = alloca (strlen(msg) + 5 );
>  		struct throughput *tp = progress->throughput;
>  		if (tp) {
>  			unsigned int rate = !tp->avg_misecs ? 0 :

I do not know the situation over there these days, but I have a distant
but bitter memory of having to deal with AIX X-<.  It insisted that
inclusion of <alloca.h> to be the very first thing in the source before
anything else.  I would want to keep alloca() out of the codebase without
very good reason.  Not that I care much about portability to AIX, but not
having to worry about alloca() unless necessary is a good thing.

I do not think progress_msg() is a good reason to even worrying about a
dynamically sized array.  The function is designed to spit out a single
line of message (so the incoming msg is expected to be shorter than 80
chars or so).  If you "git grep stop_progress_msg", you will see that
there are only two callers of this function, one in progress.c itself that
says "done", and the other one in index-pack.c that gives a string
formatted into 48-byte buffer.

So we can be lazy and say:

	char buf[128];
        ...
        snprintf(buf, sizeof(buf), ", %s.\n", msg)

and be done with it.

If you really wanted to be safe and anal, you could do something like
this, which would be just as efficient and much more straightforward:

 progress.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/progress.c b/progress.c
index d19f80c..55a8687 100644
--- a/progress.c
+++ b/progress.c
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
 	*p_progress = NULL;
 	if (progress->last_value != -1) {
 		/* Force the last update */
-		char buf[strlen(msg) + 5];
+		char buf[128], *bufp;
+		size_t len = strlen(msg) + 5;
 		struct throughput *tp = progress->throughput;
+
+		bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
 		if (tp) {
 			unsigned int rate = !tp->avg_misecs ? 0 :
 					tp->avg_bytes / tp->avg_misecs;
 			throughput_string(tp, tp->curr_total, rate);
 		}
 		progress_update = 1;
-		sprintf(buf, ", %s.\n", msg);
-		display(progress, progress->last_value, buf);
+		sprintf(bufp, ", %s.\n", msg);
+		display(progress, progress->last_value, bufp);
+		if (buf != bufp)
+			free(bufp);
 	}
 	clear_progress_signal();
 	free(progress->throughput);

  parent reply	other threads:[~2008-06-06 23:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-06 19:34 [PATCH] This patch is to allow 12 different OS's to compile and run git Boyd Lynn Gerber
2008-06-06 19:39 ` Jeremy Maitin-Shepard
2008-06-06 20:02   ` Boyd Lynn Gerber
2008-06-06 20:15     ` Stephan Beyer
2008-06-06 20:28       ` Linus Torvalds
2008-06-06 20:44         ` Boyd Lynn Gerber
2008-06-06 22:16     ` Brandon Casey
2008-06-06 23:08     ` Junio C Hamano [this message]
2008-06-06 23:23       ` Boyd Lynn Gerber
2008-06-07  0:38         ` [PATCH] 0002 " Boyd Lynn Gerber
2008-06-07  0:47           ` Daniel Barkalow
2008-06-07  1:25             ` [PATCH] 0003 " Boyd Lynn Gerber
2008-06-07  2:12               ` Junio C Hamano
2008-06-07  2:40                 ` Boyd Lynn Gerber
2008-06-07  3:40                   ` Daniel Barkalow
2008-06-08  3:46                     ` Boyd Lynn Gerber
2008-06-08  7:45                       ` Junio C Hamano
2008-06-08 16:57                         ` [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
2008-06-08 17:07                         ` [PATCH] Port to 12 other Platforms Boyd Lynn Gerber
2008-06-08  3:50                     ` [PATCH] 0004 This patch is to allow 12 different OS's to compile and run git Boyd Lynn Gerber
2008-06-08  7:22                       ` Boyd Lynn Gerber
2008-06-06 19:46 ` [PATCH] " Thomas Harning
2008-06-06 22:58 ` Daniel Barkalow
2008-06-06 23:17   ` Boyd Lynn Gerber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vmylyrwkg.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=gerberb@zenez.com \
    --cc=git@vger.kernel.org \
    --cc=harningt@gmail.com \
    --cc=jbms@cmu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).