git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Keeping <john@keeping.me.uk>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Antoine Pelisse <apelisse@gmail.com>
Subject: Re: [PATCH 2/3] combine-diff: suppress a clang warning
Date: Sun, 3 Feb 2013 23:15:49 +0000	[thread overview]
Message-ID: <20130203231549.GV1342@serenity.lan> (raw)
In-Reply-To: <7v8v7585sr.fsf@alter.siamese.dyndns.org>

On Sun, Feb 03, 2013 at 01:07:48PM -0800, Junio C Hamano wrote:
> John Keeping <john@keeping.me.uk> writes:
> 
> > A quick search turned up the original thread where this feature was
> > added to Clang [1].  It seems that it does find genuine bugs where
> > people try to log values by doing:
> >
> >     log("failed to handle error: " + errno);
> 
> To be perfectly honest, anybody who writes such a code should be
> sent back to school before trying to touch out code ever again ;-).

Yeah, I can't see that getting through review here :-).

> It is not even valid Python, Perl nor Java, I would think.

It is valid Java, although I can't think of any other languages that let
you do that.

> > Are you happy to change COLONS to a const char[] instead of a #define?
> 
> Happy?  Not really.
> 
> It could be a good change for entirely different reason. We will
> save space if we ever need to use it in multiple places.  But the
> entire "COLONS + offset" thing was a hack we did, knowing that it
> will break when we end up showing a muiti-way diff for more than 32
> blobs.
> 
> If we were to be touching that area of code, I'd rather see a change
> to make it more robust against such a corner case.  If it results in
> squelching misguided clang warnings against programmers who should
> not be writing in C, that is a nice side effect, but I loathe to see
> any change whose primary purpose is to squelch pointless warnings.

This seems like a sensible change.

I generally like to get rid of the pointless warnings so that the useful
ones can't hide in the noise.  Perhaps "CFLAGS += -Wno-string-plus-int"
would be better for this particular warning, but when there's only one
bit of code that triggers it, tweaking that seemed simpler.

>  combine-diff.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/combine-diff.c b/combine-diff.c
> index bb1cc96..7f6187f 100644
> --- a/combine-diff.c
> +++ b/combine-diff.c
> @@ -982,14 +982,10 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
>  	free(sline);
>  }
>  
> -#define COLONS "::::::::::::::::::::::::::::::::"
> -
>  static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev)
>  {
>  	struct diff_options *opt = &rev->diffopt;
> -	int i, offset;
> -	const char *prefix;
> -	int line_termination, inter_name_termination;
> +	int line_termination, inter_name_termination, i;
>  
>  	line_termination = opt->line_termination;
>  	inter_name_termination = '\t';
> @@ -1000,17 +996,14 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
>  		show_log(rev);
>  
>  	if (opt->output_format & DIFF_FORMAT_RAW) {
> -		offset = strlen(COLONS) - num_parent;
> -		if (offset < 0)
> -			offset = 0;
> -		prefix = COLONS + offset;
> +		/* As many colons as there are parents */
> +		for (i = 0; i < num_parent; i++)
> +			putchar(':');
>  
>  		/* Show the modes */
> -		for (i = 0; i < num_parent; i++) {
> -			printf("%s%06o", prefix, p->parent[i].mode);
> -			prefix = " ";
> -		}
> -		printf("%s%06o", prefix, p->mode);
> +		for (i = 0; i < num_parent; i++)
> +			printf("%06o ", p->parent[i].mode);
> +		printf("%06o", p->mode);
>  
>  		/* Show sha1's */
>  		for (i = 0; i < num_parent; i++)

  reply	other threads:[~2013-02-03 23:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-03 14:37 [PATCH 0/3] Make Git compile warning-free with Clang John Keeping
2013-02-03 14:37 ` [PATCH 1/3] fix clang -Wtautological-compare with unsigned enum John Keeping
2013-02-03 19:38   ` Jonathan Nieder
2013-02-03 14:37 ` [PATCH 2/3] combine-diff: suppress a clang warning John Keeping
2013-02-03 18:20   ` Tay Ray Chuan
2013-02-03 19:06     ` John Keeping
2013-02-03 19:58   ` Junio C Hamano
2013-02-03 20:31     ` John Keeping
2013-02-03 21:07       ` Junio C Hamano
2013-02-03 23:15         ` John Keeping [this message]
2013-02-04  0:24           ` Junio C Hamano
2013-02-05 20:25             ` [PATCH] t4038: add tests for "diff --cc --raw <trees>" John Keeping
2013-02-05 20:48               ` Junio C Hamano
2013-02-05 21:39                 ` [PATCH v2] " John Keeping
2013-02-05 22:27                   ` Junio C Hamano
2013-02-07  4:12           ` [PATCH 2/3] combine-diff: suppress a clang warning Miles Bader
2013-02-07  8:41             ` John Keeping
2013-02-03 14:37 ` [PATCH 3/3] builtin/apply: tighten (dis)similarity index parsing John Keeping
2013-02-03 20:50   ` Junio C Hamano
2013-02-03 17:13 ` [PATCH 0/3] Make Git compile warning-free with Clang Antoine Pelisse

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=20130203231549.GV1342@serenity.lan \
    --to=john@keeping.me.uk \
    --cc=apelisse@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).