* [PATCH] diff: remove another ternary expression always evaluating to true @ 2013-08-08 18:55 Stefan Beller 2013-08-08 21:01 ` Johannes Schindelin 2013-08-08 21:36 ` [PATCH] diff: remove another ternary expression always evaluating to true Philip Oakley 0 siblings, 2 replies; 8+ messages in thread From: Stefan Beller @ 2013-08-08 18:55 UTC (permalink / raw) To: Jens.Lehmann, johannes.schindelin, gitster, git; +Cc: Stefan Beller The condition before the changed line dereferences 'one' to query the mode, so if the condition evaluates to true, the variable one must not be null. Therefore we do not need the ternary operator depending on one, giving either one->path or two->path. This always evaluates to one->path, so we can remove the ternary operator. The condition and the usage of the ternary operator have been introduced by the same commit (752c0c24, 2009-10-19, Add the --submodule option to the diff option family). As that commit message refers to a GitTogether I'd assume that patch was crafted in a hurry, so maybe overlooking the need for a ternary operator there. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> --- diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 80f8439..f30b7e4 100644 --- a/diff.c +++ b/diff.c @@ -2252,8 +2252,7 @@ static void builtin_diff(const char *name_a, (!two->mode || S_ISGITLINK(two->mode))) { const char *del = diff_get_color_opt(o, DIFF_FILE_OLD); const char *add = diff_get_color_opt(o, DIFF_FILE_NEW); - show_submodule_summary(o->file, one ? one->path : two->path, - line_prefix, + show_submodule_summary(o->file, one->path, line_prefix, one->sha1, two->sha1, two->dirty_submodule, meta, del, add, reset); return; -- 1.8.4.rc1.25.gd121ba2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 18:55 [PATCH] diff: remove another ternary expression always evaluating to true Stefan Beller @ 2013-08-08 21:01 ` Johannes Schindelin 2013-08-08 21:22 ` Stefan Beller 2013-08-08 21:36 ` [PATCH] diff: remove another ternary expression always evaluating to true Philip Oakley 1 sibling, 1 reply; 8+ messages in thread From: Johannes Schindelin @ 2013-08-08 21:01 UTC (permalink / raw) To: Stefan Beller; +Cc: Jens.Lehmann, gitster, git Hi Stefan, On Thu, 8 Aug 2013, Stefan Beller wrote: > The condition before the changed line dereferences 'one' to query the mode, > so if the condition evaluates to true, the variable one must not be null. To show this better, please use -U10 (or some other appropriate context option) in the future. > Therefore we do not need the ternary operator depending on one, giving > either one->path or two->path. This always evaluates to one->path, so we > can remove the ternary operator. > > The condition and the usage of the ternary operator have been introduced > by the same commit (752c0c24, 2009-10-19, Add the --submodule option to > the diff option family). As that commit message refers to a GitTogether > I'd assume that patch was crafted in a hurry, so maybe overlooking the > need for a ternary operator there. If this is my code, I do not need a GitTogether to excuse my sloppiness. In this particular case, I imagine the appropriate fix is to test for one->path instead of removing the conditional, though. Ciao, Johannes ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 21:01 ` Johannes Schindelin @ 2013-08-08 21:22 ` Stefan Beller 2013-08-08 21:36 ` Johannes Schindelin 0 siblings, 1 reply; 8+ messages in thread From: Stefan Beller @ 2013-08-08 21:22 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Jens.Lehmann, gitster, git [-- Attachment #1: Type: text/plain, Size: 3721 bytes --] On 08/08/2013 11:01 PM, Johannes Schindelin wrote: > Hi Stefan, > > On Thu, 8 Aug 2013, Stefan Beller wrote: > >> The condition before the changed line dereferences 'one' to query the mode, >> so if the condition evaluates to true, the variable one must not be null. > > To show this better, please use -U10 (or some other appropriate context > option) in the future. > >> Therefore we do not need the ternary operator depending on one, giving >> either one->path or two->path. This always evaluates to one->path, so we >> can remove the ternary operator. >> >> The condition and the usage of the ternary operator have been introduced >> by the same commit (752c0c24, 2009-10-19, Add the --submodule option to >> the diff option family). As that commit message refers to a GitTogether >> I'd assume that patch was crafted in a hurry, so maybe overlooking the >> need for a ternary operator there. > > If this is my code, I do not need a GitTogether to excuse my sloppiness. > In this particular case, I imagine the appropriate fix is to test for > one->path instead of removing the conditional, though. > > Ciao, > Johannes > Ok, here is a resend with -U10 I forgot about the -U10 as gitk shows a different number of lines of context around. Is there a way to configure gitk to show less lines of code or a default -U10 for send-email/format-patch? So you rather propose to have - show_submodule_summary(o->file, one ? one->path : two->path, + show_submodule_summary(o->file, one->path ? one->path : two->path, instead of the patch below? (The test suite run without any problem using that patch) Stefan --8<-- From 3a580c51f0bf70745f26eb5045d646dfead2afd3 Mon Sep 17 00:00:00 2001 From: Stefan Beller <stefanbeller@googlemail.com> Date: Thu, 8 Aug 2013 20:54:24 +0200 Subject: [PATCH] diff: remove another ternary expression always evaluating to true The condition before the changed line dereferences 'one' to query the mode, so if the condition evaluates to true, the variable one must not be null. Therefore we do not need the ternary operator depending on one, giving either one->path or two->path. This always evaluates to one->path, so we can remove the ternary operator. The condition and the usage of the ternary operator have been introduced by the same commit (752c0c24, 2009-10-19, Add the --submodule option to the diff option family). As that commit message refers to a GitTogether I'd assume that patch was crafted in a hurry, so maybe overlooking the need for a ternary operator there. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> --- diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 80f8439..f30b7e4 100644 --- a/diff.c +++ b/diff.c @@ -2245,22 +2245,21 @@ static void builtin_diff(const char *name_a, struct userdiff_driver *textconv_one = NULL; struct userdiff_driver *textconv_two = NULL; struct strbuf header = STRBUF_INIT; const char *line_prefix = diff_line_prefix(o); if (DIFF_OPT_TST(o, SUBMODULE_LOG) && (!one->mode || S_ISGITLINK(one->mode)) && (!two->mode || S_ISGITLINK(two->mode))) { const char *del = diff_get_color_opt(o, DIFF_FILE_OLD); const char *add = diff_get_color_opt(o, DIFF_FILE_NEW); - show_submodule_summary(o->file, one ? one->path : two->path, - line_prefix, + show_submodule_summary(o->file, one->path, line_prefix, one->sha1, two->sha1, two->dirty_submodule, meta, del, add, reset); return; } if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) { textconv_one = get_textconv(one); textconv_two = get_textconv(two); } -- 1.8.4.rc1.25.gd121ba2 [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 899 bytes --] ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 21:22 ` Stefan Beller @ 2013-08-08 21:36 ` Johannes Schindelin 2013-08-08 22:03 ` Junio C Hamano 0 siblings, 1 reply; 8+ messages in thread From: Johannes Schindelin @ 2013-08-08 21:36 UTC (permalink / raw) To: Stefan Beller; +Cc: Jens.Lehmann, gitster, git Hi Stefan, On Thu, 8 Aug 2013, Stefan Beller wrote: > So you rather propose to have > - show_submodule_summary(o->file, one ? one->path : two->path, > + show_submodule_summary(o->file, one->path ? one->path : two->path, I do. The reason is that one->path could be NULL (but not both one->path and two->path) and the summary would not be as helpful as possible if it wrote "(null)" instead of the path of the submodule. Ciao, Johannes ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 21:36 ` Johannes Schindelin @ 2013-08-08 22:03 ` Junio C Hamano 2013-08-08 22:11 ` [PATCH] diff: fix a possible null pointer dereference Stefan Beller 0 siblings, 1 reply; 8+ messages in thread From: Junio C Hamano @ 2013-08-08 22:03 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Stefan Beller, Jens.Lehmann, git Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > Hi Stefan, > > On Thu, 8 Aug 2013, Stefan Beller wrote: > >> So you rather propose to have >> - show_submodule_summary(o->file, one ? one->path : two->path, >> + show_submodule_summary(o->file, one->path ? one->path : two->path, > > I do. The reason is that one->path could be NULL (but not both one->path > and two->path) and the summary would not be as helpful as possible if it > wrote "(null)" instead of the path of the submodule. Good. Also some C libraries would choke when asked to %s format a NULL, instead of giving "(null)" to avoid segfaulting (which I think is a quirk in glibc). ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] diff: fix a possible null pointer dereference 2013-08-08 22:03 ` Junio C Hamano @ 2013-08-08 22:11 ` Stefan Beller 0 siblings, 0 replies; 8+ messages in thread From: Stefan Beller @ 2013-08-08 22:11 UTC (permalink / raw) To: gitster, Jens.Lehmann, Johannes.Schindelin, git; +Cc: Stefan Beller The condition in the ternary operator was wrong, hence the wrong char pointer could be used as the parameter for show_submodule_summary. one->path may be null, but we definitely need a non null path given to the function. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> Acked-By: Johannes Schindelin <Johannes.Schindelin@gmx.de> --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 80f8439..061694b 100644 --- a/diff.c +++ b/diff.c @@ -2252,7 +2252,7 @@ static void builtin_diff(const char *name_a, (!two->mode || S_ISGITLINK(two->mode))) { const char *del = diff_get_color_opt(o, DIFF_FILE_OLD); const char *add = diff_get_color_opt(o, DIFF_FILE_NEW); - show_submodule_summary(o->file, one ? one->path : two->path, + show_submodule_summary(o->file, one->path ? one->path : two->path, line_prefix, one->sha1, two->sha1, two->dirty_submodule, meta, del, add, reset); -- 1.8.4.rc1.25.gd121ba2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 18:55 [PATCH] diff: remove another ternary expression always evaluating to true Stefan Beller 2013-08-08 21:01 ` Johannes Schindelin @ 2013-08-08 21:36 ` Philip Oakley 2013-08-08 22:17 ` Stefan Beller 1 sibling, 1 reply; 8+ messages in thread From: Philip Oakley @ 2013-08-08 21:36 UTC (permalink / raw) To: Stefan Beller, git; +Cc: Jens.Lehmann, johannes.schindelin, gitster From: "Stefan Beller" <stefanbeller@googlemail.com> Sent: Thursday, August 08, 2013 7:55 PM Subject: [PATCH] diff: remove another ternary expression always evaluating to true Have these issues (and the earlier expression simplifications patches $gmane/231916, $gmane/231912 ) been discovered with the "STACK" tool I'd noted in $gmane/230542 which you were also interested in (I've not had chance to run the tool). If so, it's probably worth referencing the tool and the paper which explains the broader issues. Philip > The condition before the changed line dereferences 'one' to query the > mode, > so if the condition evaluates to true, the variable one must not be > null. > Therefore we do not need the ternary operator depending on one, giving > either one->path or two->path. This always evaluates to one->path, so > we can remove the ternary operator. > > The condition and the usage of the ternary operator have been > introduced > by the same commit (752c0c24, 2009-10-19, Add the --submodule option > to > the diff option family). As that commit message refers to a > GitTogether > I'd assume that patch was crafted in a hurry, so maybe overlooking the > need for a ternary operator there. > > Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> > --- > diff.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/diff.c b/diff.c > index 80f8439..f30b7e4 100644 > --- a/diff.c > +++ b/diff.c > @@ -2252,8 +2252,7 @@ static void builtin_diff(const char *name_a, > (!two->mode || S_ISGITLINK(two->mode))) { > const char *del = diff_get_color_opt(o, DIFF_FILE_OLD); > const char *add = diff_get_color_opt(o, DIFF_FILE_NEW); > - show_submodule_summary(o->file, one ? one->path : two->path, > - line_prefix, > + show_submodule_summary(o->file, one->path, line_prefix, > one->sha1, two->sha1, two->dirty_submodule, > meta, del, add, reset); > return; > -- > 1.8.4.rc1.25.gd121ba2 > > -- ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] diff: remove another ternary expression always evaluating to true 2013-08-08 21:36 ` [PATCH] diff: remove another ternary expression always evaluating to true Philip Oakley @ 2013-08-08 22:17 ` Stefan Beller 0 siblings, 0 replies; 8+ messages in thread From: Stefan Beller @ 2013-08-08 22:17 UTC (permalink / raw) To: Philip Oakley; +Cc: git, Jens.Lehmann, johannes.schindelin, gitster [-- Attachment #1: Type: text/plain, Size: 1213 bytes --] On 08/08/2013 11:36 PM, Philip Oakley wrote: > From: "Stefan Beller" <stefanbeller@googlemail.com> > Sent: Thursday, August 08, 2013 7:55 PM > Subject: [PATCH] diff: remove another ternary expression always > evaluating to true > > Have these issues (and the earlier expression simplifications patches > $gmane/231916, $gmane/231912 ) been discovered with the "STACK" tool I'd > noted in $gmane/230542 which you were also interested in (I've not had > chance to run the tool). > > If so, it's probably worth referencing the tool and the paper which > explains the broader issues. > > Philip > Yes, those 3 issues have been discovered using the STACK tool The paper regarding that tool can be found at http://pdos.csail.mit.edu/~xi/papers/stack-sosp13.pdf It's definitely an interesting read! (At least for me it was ;) The authors intend to make that tool available to broader public as open source in August this year, iirc. However I do not know if their repository address was already announced publicly, so I did not announce to have used it. (Last time I announced using static code analysis tools for my patches the review-process was much harder as well :D) Stefan [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 899 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-08-08 22:17 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-08-08 18:55 [PATCH] diff: remove another ternary expression always evaluating to true Stefan Beller 2013-08-08 21:01 ` Johannes Schindelin 2013-08-08 21:22 ` Stefan Beller 2013-08-08 21:36 ` Johannes Schindelin 2013-08-08 22:03 ` Junio C Hamano 2013-08-08 22:11 ` [PATCH] diff: fix a possible null pointer dereference Stefan Beller 2013-08-08 21:36 ` [PATCH] diff: remove another ternary expression always evaluating to true Philip Oakley 2013-08-08 22:17 ` Stefan Beller
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).