threads / patch / 30373

patchcheckout: squelch "'mode' may be used uninitialized in this function" warning

Subject: [PATCH] checkout: squelch "'mode' may be used uninitialized in this function" warning

## tl;dr

3 messages between Apr 30, 2012 and May 8, 2012. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

dsp@php.net· Apr 30, 2012, 22:39 UTC · lore
From: David Soria Parra <dsp@php.net>

Use a 'fake' initialization for the 'mode' variable to work around a GCC warning as in 5a7a367. The necessary condition to initialize 'mode' will always be true but cannot be checked by the compiler.

Signed-off-by: David Soria Parra <dsp@php.net>
---
 builtin/checkout.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to builtin/checkout.c +1 −1
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 84d3eb3..6b8bf31 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -157,7 +157,7 @@ static int checkout_merged(int pos, struct checkout *state)
 	unsigned char sha1[20];
 	mmbuffer_t result_buf;
 	unsigned char threeway[3][20];
-	unsigned mode;
+	unsigned mode = mode;
 
 	memset(threeway, 0, sizeof(threeway));
 	while (pos < active_nr) {
-- 
1.7.8.GIT
David Soria Parra· May 3, 2012, 10:59 UTC · re: dsp@php.net · lore

Re: [PATCH] checkout: squelch "'mode' may be used uninitialized in this function" warning

Any update on this patch? Is it going to maint?
On 2012-04-30, dsp@php.net <dsp@php.net> wrote:
Show 24 quoted lines
> From: David Soria Parra <dsp@php.net>
>
> Use a 'fake' initialization for the 'mode' variable to work around a
> GCC warning as in 5a7a367. The necessary condition to initialize 'mode'
> will always be true but cannot be checked by the compiler.
>
> Signed-off-by: David Soria Parra <dsp@php.net>
> ---
>  builtin/checkout.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 84d3eb3..6b8bf31 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -157,7 +157,7 @@ static int checkout_merged(int pos, struct checkout *state)
>  	unsigned char sha1[20];
>  	mmbuffer_t result_buf;
>  	unsigned char threeway[3][20];
> -	unsigned mode;
> +	unsigned mode = mode;
>  
>  	memset(threeway, 0, sizeof(threeway));
>  	while (pos < active_nr) {
Jeff King· May 8, 2012, 20:26 UTC · re: David Soria Parra · lore

Re: [PATCH] checkout: squelch "'mode' may be used uninitialized in this function" warning

On Thu, May 03, 2012 at 10:59:24AM +0000, David Soria Parra wrote:
> Any update on this patch? Is it going to maint?
I doubt it:
Show 10 quoted lines
> > diff --git a/builtin/checkout.c b/builtin/checkout.c
> > index 84d3eb3..6b8bf31 100644
> > --- a/builtin/checkout.c
> > +++ b/builtin/checkout.c
> > @@ -157,7 +157,7 @@ static int checkout_merged(int pos, struct checkout *state)
> >  	unsigned char sha1[20];
> >  	mmbuffer_t result_buf;
> >  	unsigned char threeway[3][20];
> > -	unsigned mode;
> > +	unsigned mode = mode;

What is this based on? This has been fixed since 335c6e4 (checkout_merged(): squelch false warning from some gcc, 2011-12-15), which was in v1.7.8.2.

-Peff

← back to recent threads