# Simple dead assignment

10 messages from 2011-05-24 to 2011-05-25. Participants: Chris Wilson, Matthieu Moy, Michael Schubert, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/27445

## Chris Wilson, 2011-05-24 21:07

Subject: Simple dead assignment
Message-ID: <20110524210758.GH16052@localhost>
URL: https://gitlist.dev/e/20110524210758.GH16052%40localhost

```
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


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:

```

## Chris Wilson, 2011-05-24 22:45

Subject: [PATCH] Simple dead assignment
Message-ID: <20110524224525.GI16052@localhost>
URL: https://gitlist.dev/e/20110524224525.GI16052%40localhost
In-Reply-To: <20110524210758.GH16052@localhost>

```
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:

```

## Matthieu Moy, 2011-05-25 07:52

Subject: Re: [PATCH] Simple dead assignment
Message-ID: <vpqfwo3ush3.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqfwo3ush3.fsf%40bauges.imag.fr
In-Reply-To: <20110524224525.GI16052@localhost>

```
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/

```

## Chris Wilson, 2011-05-25 15:06

Subject: [PATCH] Remove a dead assignment
Message-ID: <20110525150631.GA29161@localhost>
URL: https://gitlist.dev/e/20110525150631.GA29161%40localhost
In-Reply-To: <vpqfwo3ush3.fsf@bauges.imag.fr>

```
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

```

## Matthieu Moy, 2011-05-25 15:50

Subject: Re: [PATCH] Remove a dead assignment
Message-ID: <vpqwrhevkxz.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqwrhevkxz.fsf%40bauges.imag.fr
In-Reply-To: <20110525150631.GA29161@localhost>

```
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/

```

## Michael Schubert, 2011-05-25 17:18

Subject: Re: [PATCH] Remove a dead assignment
Message-ID: <4DDD3A01.6040407@elegosoft.com>
URL: https://gitlist.dev/e/4DDD3A01.6040407%40elegosoft.com
In-Reply-To: <20110525150631.GA29161@localhost>

```
There already is a patch on its way:

http://article.gmane.org/gmane.comp.version-control.git/174378

```

## Chris Wilson, 2011-05-25 18:45

Subject: [PATCH] Remove a dead assignment
Message-ID: <20110525184514.GA20005@localhost>
URL: https://gitlist.dev/e/20110525184514.GA20005%40localhost
In-Reply-To: <4DDD3A01.6040407@elegosoft.com>

```
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

```

## Junio C Hamano, 2011-05-25 19:11

Subject: Re: [PATCH] Remove a dead assignment
Message-ID: <7v4o4i4mte.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4o4i4mte.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20110525184514.GA20005@localhost>

```
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);
 }

```

## Junio C Hamano, 2011-05-25 19:23

Subject: Re: [PATCH] Remove a dead assignment
Message-ID: <7vzkma37pb.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzkma37pb.fsf%40alter.siamese.dyndns.org
In-Reply-To: <7v4o4i4mte.fsf@alter.siamese.dyndns.org>

```
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);
 }
 

```

## Jeff King, 2011-05-25 19:45

Subject: Re: [PATCH] Remove a dead assignment
Message-ID: <20110525194505.GB27260@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110525194505.GB27260%40sigill.intra.peff.net
In-Reply-To: <7vzkma37pb.fsf@alter.siamese.dyndns.org>

```
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

```
