* Simple dead assignment @ 2011-05-24 21:07 Chris Wilson 2011-05-24 22:45 ` [PATCH] " Chris Wilson 0 siblings, 1 reply; 10+ messages in thread From: Chris Wilson @ 2011-05-24 21:07 UTC (permalink / raw) To: git; +Cc: Ævar Arnfjörð Bjarmason, Junio C Hamano [-- Attachment #1: Type: text/plain, Size: 331 bytes --] Hi Folks, Sentry picked up this dead assignment commited yesterday in ba67aaf. I've provided a patch to remove it. It might also be a good idea to ask the author if that value was supposed to be used for something in particular before pulling it out. Thanks, Chris -- Chris Wilson http://vigilantsw.com/ Vigilant Software, LLC [-- Attachment #2: da.diff --] [-- Type: text/x-diff, Size: 653 bytes --] diff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c index 7125093..5829463 100644 --- a/sh-i18n--envsubst.c +++ b/sh-i18n--envsubst.c @@ -67,9 +67,6 @@ static void subst_from_stdin (void); int main (int argc, char *argv[]) { - /* Default values for command line options. */ - unsigned short int show_variables = 0; - switch (argc) { case 1: @@ -88,7 +85,6 @@ main (int argc, char *argv[]) /* git sh-i18n--envsubst --variables '$foo and $bar' */ if (strcmp(argv[1], "--variables")) error ("first argument must be --variables when two are given"); - show_variables = 1; print_variables (argv[2]); break; default: ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH] Simple dead assignment 2011-05-24 21:07 Simple dead assignment Chris Wilson @ 2011-05-24 22:45 ` Chris Wilson 2011-05-25 7:52 ` Matthieu Moy 0 siblings, 1 reply; 10+ messages in thread From: Chris Wilson @ 2011-05-24 22:45 UTC (permalink / raw) To: git; +Cc: Ævar Arnfjörð Bjarmason, Junio C Hamano On Tue, May 24, 2011 at 05:07:58PM -0400, Chris Wilson wrote: > Sentry picked up this dead assignment commited yesterday in ba67aaf. > I've provided a patch to remove it. It might also be a good idea to > ask the author if that value was supposed to be used for something > in particular before pulling it out. Oops, I see others putting the patches inline. Here you go. Chris -- Chris Wilson http://vigilantsw.com/ Vigilant Software, LLC diff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c index 7125093..5829463 100644 --- a/sh-i18n--envsubst.c +++ b/sh-i18n--envsubst.c @@ -67,9 +67,6 @@ static void subst_from_stdin (void); int main (int argc, char *argv[]) { - /* Default values for command line options. */ - unsigned short int show_variables = 0; - switch (argc) { case 1: @@ -88,7 +85,6 @@ main (int argc, char *argv[]) /* git sh-i18n--envsubst --variables '$foo and $bar' */ if (strcmp(argv[1], "--variables")) error ("first argument must be --variables when two are given"); - show_variables = 1; print_variables (argv[2]); break; default: ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Simple dead assignment 2011-05-24 22:45 ` [PATCH] " Chris Wilson @ 2011-05-25 7:52 ` Matthieu Moy 2011-05-25 15:06 ` [PATCH] Remove a " Chris Wilson 0 siblings, 1 reply; 10+ messages in thread From: Matthieu Moy @ 2011-05-25 7:52 UTC (permalink / raw) To: Chris Wilson; +Cc: git, Ævar Arnfjörð Bjarmason, Junio C Hamano Chris Wilson <cwilson@vigilantsw.com> writes: > Oops, I see others putting the patches inline. Here you go. Please, read Documentation/SubmittingPatches. Especially read about signed-off-by and the way patches should be formatted (git send-email would help). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] Remove a dead assignment 2011-05-25 7:52 ` Matthieu Moy @ 2011-05-25 15:06 ` Chris Wilson 2011-05-25 15:50 ` Matthieu Moy 2011-05-25 17:18 ` Michael Schubert 0 siblings, 2 replies; 10+ messages in thread From: Chris Wilson @ 2011-05-25 15:06 UTC (permalink / raw) To: Matthieu Moy; +Cc: git, Ævar Arnfjörð Bjarmason, Junio C Hamano On Wed, May 25, 2011 at 09:52:56AM +0200, Matthieu Moy wrote: > Chris Wilson <cwilson@vigilantsw.com> writes: > > > Oops, I see others putting the patches inline. Here you go. > > Please, read Documentation/SubmittingPatches. Especially read about > signed-off-by and the way patches should be formatted (git send-email > would help). Thanks, trying this again. Like I said before, the author should investigate if this variable should have been used before removing it. Signed-off-by: Chris Wilson <cwilson@vigilantsw.com> --- sh-i18n--envsubst.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-) diff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c index 7125093..5829463 100644 --- a/sh-i18n--envsubst.c +++ b/sh-i18n--envsubst.c @@ -67,9 +67,6 @@ static void subst_from_stdin (void); int main (int argc, char *argv[]) { - /* Default values for command line options. */ - unsigned short int show_variables = 0; - switch (argc) { case 1: @@ -88,7 +85,6 @@ main (int argc, char *argv[]) /* git sh-i18n--envsubst --variables '$foo and $bar' */ if (strcmp(argv[1], "--variables")) error ("first argument must be --variables when two are given"); - show_variables = 1; print_variables (argv[2]); break; default: -- 1.7.5.2.354.g19aea ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Remove a dead assignment 2011-05-25 15:06 ` [PATCH] Remove a " Chris Wilson @ 2011-05-25 15:50 ` Matthieu Moy 2011-05-25 17:18 ` Michael Schubert 1 sibling, 0 replies; 10+ messages in thread From: Matthieu Moy @ 2011-05-25 15:50 UTC (permalink / raw) To: Chris Wilson; +Cc: git, Ævar Arnfjörð Bjarmason, Junio C Hamano Chris Wilson <cwilson@vigilantsw.com> writes: > On Wed, May 25, 2011 at 09:52:56AM +0200, Matthieu Moy wrote: >> Chris Wilson <cwilson@vigilantsw.com> writes: >> >> > Oops, I see others putting the patches inline. Here you go. >> >> Please, read Documentation/SubmittingPatches. Especially read about >> signed-off-by and the way patches should be formatted (git send-email >> would help). > > Thanks, trying this again. Still not right ;-). The text here (above ---) will become the commit message when applied, and you don't want the commit message to mention this discussion. This discussion could have been added below ... > Like I said before, the author should investigate if this variable > should have been used before removing it. > > Signed-off-by: Chris Wilson <cwilson@vigilantsw.com> > --- => this is the place for informal discussions. > sh-i18n--envsubst.c | 4 ---- > 1 files changed, 0 insertions(+), 4 deletions(-) If you don't follow this, then the maintainer has to do this manually, and we all prefer his time to be invested in better activities ;-). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Remove a dead assignment 2011-05-25 15:06 ` [PATCH] Remove a " Chris Wilson 2011-05-25 15:50 ` Matthieu Moy @ 2011-05-25 17:18 ` Michael Schubert 2011-05-25 18:45 ` Chris Wilson 1 sibling, 1 reply; 10+ messages in thread From: Michael Schubert @ 2011-05-25 17:18 UTC (permalink / raw) To: Chris Wilson Cc: Matthieu Moy, git, Ævar Arnfjörð Bjarmason, Junio C Hamano There already is a patch on its way: http://article.gmane.org/gmane.comp.version-control.git/174378 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] Remove a dead assignment 2011-05-25 17:18 ` Michael Schubert @ 2011-05-25 18:45 ` Chris Wilson 2011-05-25 19:11 ` Junio C Hamano 0 siblings, 1 reply; 10+ messages in thread From: Chris Wilson @ 2011-05-25 18:45 UTC (permalink / raw) To: Michael Schubert Cc: Matthieu Moy, git, Ævar Arnfjörð Bjarmason, Junio C Hamano The assignment to fmt is dead and is also useless. Signed-off-by: Chris Wilson <cwilson@vigilantsw.com> --- On Wed, May 25, 2011 at 07:18:57PM +0200, Michael Schubert wrote: > There already is a patch on its way: > > http://article.gmane.org/gmane.comp.version-control.git/174378 Thanks! Well, I wasn't going to report this dead assignment since it wasn't done recently, but now I want to figure out how to properly submit a patch. :) Am I there yet? and thanks for the help. Thanks, CHris pretty.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/pretty.c b/pretty.c index dff5c8d..5667c7f 100644 --- a/pretty.c +++ b/pretty.c @@ -1082,7 +1082,6 @@ void userformat_find_requirements(const char *fmt, struct userformat_ if (!fmt) { if (!user_format) return; - fmt = user_format; } strbuf_expand(&dummy, user_format, userformat_want_item, w); strbuf_release(&dummy); -- 1.7.5.2.354.g19aea ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Remove a dead assignment 2011-05-25 18:45 ` Chris Wilson @ 2011-05-25 19:11 ` Junio C Hamano 2011-05-25 19:23 ` Junio C Hamano 0 siblings, 1 reply; 10+ messages in thread From: Junio C Hamano @ 2011-05-25 19:11 UTC (permalink / raw) To: Chris Wilson Cc: Johannes Gilger, Michael Schubert, Matthieu Moy, git, Ævar Arnfjörð Bjarmason Chris Wilson <cwilson@vigilantsw.com> writes: > Thanks! Well, I wasn't going to report this dead assignment since > it wasn't done recently, but now I want to figure out how to properly > submit a patch. :) Am I there yet? and thanks for the help. The compiler does not understand the meaning of the code, so after seeing such a "set but unused" statement, you should wonder why such a seemingly useless statement is there, before sending a mechanical patch to remove it without thinking things through. > pretty.c | 1 - > 1 files changed, 0 insertions(+), 1 deletions(-) > > diff --git a/pretty.c b/pretty.c > index dff5c8d..5667c7f 100644 > --- a/pretty.c > +++ b/pretty.c > @@ -1082,7 +1082,6 @@ void userformat_find_requirements(const char *fmt, struct userformat_ > if (!fmt) { > if (!user_format) > return; > - fmt = user_format; > } > strbuf_expand(&dummy, user_format, userformat_want_item, w); > strbuf_release(&dummy); The if statement says "we might be passing NULL in fmt and in that case please fall back to user_format" to human readers, but the compiler is too stupid to infer such an intention, so you have to help it with your brain. I have to wonder if the strbuf_expand() should be passing fmt instead of user_format. "git blame -L1082,+7 pretty.c" points at 5b16360 (pretty: Initialize notes if %N is used, 2010-04-13). The only callsite that is introduced by that patch passes NULL to fmt, so a better fix might be to do something like this instead. builtin/log.c | 3 +-- commit.h | 2 +- pretty.c | 10 ++++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index f621990..9e05d46 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -110,8 +110,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (argc > 1) die("unrecognized argument: %s", argv[1]); - memset(&w, 0, sizeof(w)); - userformat_find_requirements(NULL, &w); + userformat_find_requirements(&w); if (!rev->show_notes_given && (!rev->pretty_given || w.notes)) rev->show_notes = 1; diff --git a/commit.h b/commit.h index 3114bd1..b652c22 100644 --- a/commit.h +++ b/commit.h @@ -92,7 +92,7 @@ extern char *reencode_commit_message(const struct commit *commit, extern void get_commit_format(const char *arg, struct rev_info *); extern const char *format_subject(struct strbuf *sb, const char *msg, const char *line_separator); -extern void userformat_find_requirements(const char *fmt, struct userformat_want *w); +extern void userformat_find_requirements(struct userformat_want *w); extern void format_commit_message(const struct commit *commit, const char *format, struct strbuf *sb, const struct pretty_print_context *context); diff --git a/pretty.c b/pretty.c index dff5c8d..ca24925 100644 --- a/pretty.c +++ b/pretty.c @@ -1075,15 +1075,13 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, return 0; } -void userformat_find_requirements(const char *fmt, struct userformat_want *w) +void userformat_find_requirements(struct userformat_want *w) { struct strbuf dummy = STRBUF_INIT; - if (!fmt) { - if (!user_format) - return; - fmt = user_format; - } + memset(w, 0, sizeof(*w)); + if (!user_format) + return; strbuf_expand(&dummy, user_format, userformat_want_item, w); strbuf_release(&dummy); } ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Remove a dead assignment 2011-05-25 19:11 ` Junio C Hamano @ 2011-05-25 19:23 ` Junio C Hamano 2011-05-25 19:45 ` Jeff King 0 siblings, 1 reply; 10+ messages in thread From: Junio C Hamano @ 2011-05-25 19:23 UTC (permalink / raw) To: Junio C Hamano Cc: Chris Wilson, Johannes Gilger, Michael Schubert, Matthieu Moy, git, Ævar Arnfjörð Bjarmason Junio C Hamano <gitster@pobox.com> writes: > The if statement says "we might be passing NULL in fmt and in that case > please fall back to user_format" to human readers, but the compiler is too > stupid to infer such an intention, so you have to help it with your brain. > I have to wonder if the strbuf_expand() should be passing fmt instead of > user_format. "git blame -L1082,+7 pretty.c" points at 5b16360 (pretty: > Initialize notes if %N is used, 2010-04-13). > > The only callsite that is introduced by that patch passes NULL to fmt, so > a better fix might be to do something like this instead. If somebody cares about the reusability of the code for other callsites added in the future, we could do this instead. I think this is what Johannes wanted to do from the beginning, and is a better fix than my previous one to remove the fmt parameter altogether. -- >8 -- Subject: userformat_find_requirements(): find requirement for the correct format This function was introduced in 5b16360 (pretty: Initialize notes if %N is used, 2010-04-13) to check what kind of information the "log --format=..." user format string wants. The function can be passed a NULL instead of a format string to ask it to check user_format variable kept by an earlier call to save_user_format(). But it unconditionally checked user_format and not the string it was given. The only caller introduced by the change passes NULL, which kept the bug unnoticed, until a new GCC noticed that there is an assignment to fmt that is never used. Noticed-by: Chris Wilson's compiler Signed-off-by: Junio C Hamano <gitster@pobox.com> --- pretty.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pretty.c b/pretty.c index dff5c8d..52174fd 100644 --- a/pretty.c +++ b/pretty.c @@ -1084,7 +1084,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w) return; fmt = user_format; } - strbuf_expand(&dummy, user_format, userformat_want_item, w); + strbuf_expand(&dummy, fmt, userformat_want_item, w); strbuf_release(&dummy); } ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Remove a dead assignment 2011-05-25 19:23 ` Junio C Hamano @ 2011-05-25 19:45 ` Jeff King 0 siblings, 0 replies; 10+ messages in thread From: Jeff King @ 2011-05-25 19:45 UTC (permalink / raw) To: Junio C Hamano Cc: Chris Wilson, Johannes Gilger, Michael Schubert, Matthieu Moy, git, Ævar Arnfjörð Bjarmason On Wed, May 25, 2011 at 12:23:44PM -0700, Junio C Hamano wrote: > Junio C Hamano <gitster@pobox.com> writes: > > > The if statement says "we might be passing NULL in fmt and in that case > > please fall back to user_format" to human readers, but the compiler is too > > stupid to infer such an intention, so you have to help it with your brain. > > I have to wonder if the strbuf_expand() should be passing fmt instead of > > user_format. "git blame -L1082,+7 pretty.c" points at 5b16360 (pretty: > > Initialize notes if %N is used, 2010-04-13). > > > > The only callsite that is introduced by that patch passes NULL to fmt, so > > a better fix might be to do something like this instead. > > If somebody cares about the reusability of the code for other callsites > added in the future, we could do this instead. > > I think this is what Johannes wanted to do from the beginning, and is a > better fix than my previous one to remove the fmt parameter altogether. Actually, I am to blame for this interface, see: http://article.gmane.org/gmane.comp.version-control.git/144650 and my response: http://article.gmane.org/gmane.comp.version-control.git/144715 The resulting patch definitely has a bug (albeit one that could not be triggered by current users), and should have had this: > - strbuf_expand(&dummy, user_format, userformat_want_item, w); > + strbuf_expand(&dummy, fmt, userformat_want_item, w); all along. I'm also OK with just tightening the interface to always use user_format, as no callers who wanted the extra parameter have come up in the past year. > Subject: userformat_find_requirements(): find requirement for the correct format > > This function was introduced in 5b16360 (pretty: Initialize notes if %N is > used, 2010-04-13) to check what kind of information the "log --format=..." > user format string wants. The function can be passed a NULL instead of a > format string to ask it to check user_format variable kept by an earlier > call to save_user_format(). > > But it unconditionally checked user_format and not the string it was > given. The only caller introduced by the change passes NULL, which > kept the bug unnoticed, until a new GCC noticed that there is an > assignment to fmt that is never used. Acked-by: Jeff King <peff@peff.net> > Noticed-by: Chris Wilson's compiler Heh. -Peff ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-05-25 19:45 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-05-24 21:07 Simple dead assignment Chris Wilson 2011-05-24 22:45 ` [PATCH] " Chris Wilson 2011-05-25 7:52 ` Matthieu Moy 2011-05-25 15:06 ` [PATCH] Remove a " Chris Wilson 2011-05-25 15:50 ` Matthieu Moy 2011-05-25 17:18 ` Michael Schubert 2011-05-25 18:45 ` Chris Wilson 2011-05-25 19:11 ` Junio C Hamano 2011-05-25 19:23 ` Junio C Hamano 2011-05-25 19:45 ` Jeff King
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).