# [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.

6 messages from 2013-05-26 to 2013-05-28. Participants: Stefan Beller, Stefano Lattarini, Joachim Schmitz.
Thread: https://gitlist.dev/t/33943

## Stefan Beller, 2013-05-26 20:05

Subject: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <1369598719-10798-1-git-send-email-stefanbeller@googlemail.com>
URL: https://gitlist.dev/e/1369598719-10798-1-git-send-email-stefanbeller%40googlemail.com

```
Reported by cppcheck.

Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 fast-import.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fast-import.c b/fast-import.c
index 5f539d7..0142e3a 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2914,7 +2914,7 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20])
 static void parse_cat_blob(void)
 {
 	const char *p;
-	struct object_entry *oe = oe;
+	struct object_entry *oe;
 	unsigned char sha1[20];
 
 	/* cat-blob SP <object> LF */
-- 
1.8.3

```

## Stefano Lattarini, 2013-05-26 20:08

Subject: Re: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <51A26BB7.3060702@gmail.com>
URL: https://gitlist.dev/e/51A26BB7.3060702%40gmail.com
In-Reply-To: <1369598719-10798-1-git-send-email-stefanbeller@googlemail.com>

```
On 05/26/2013 10:05 PM, Stefan Beller wrote:
> Reported by cppcheck.
> 
> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
> ---
>  fast-import.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fast-import.c b/fast-import.c
> index 5f539d7..0142e3a 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -2914,7 +2914,7 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20])
>  static void parse_cat_blob(void)
>  {
>  	const char *p;
> -	struct object_entry *oe = oe;
>
This was done on purpose, to avoid spurious warnings with (at least)
some versions of GCC.

> +	struct object_entry *oe;
>  	unsigned char sha1[20];
>  
>  	/* cat-blob SP <object> LF */

Regards,
  Stefano

```

## Stefan Beller, 2013-05-26 20:14

Subject: Re: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <51A26D0D.2030702@googlemail.com>
URL: https://gitlist.dev/e/51A26D0D.2030702%40googlemail.com
In-Reply-To: <51A26BB7.3060702@gmail.com>

```
It's not done very often.
For example at the very same place of the patch there is
const char *p; not assigned.

Well you could argue, that it can be detected by gcc as that variable p
is assigned next line.
So another counterexample, having the same pattern would be
fast-import.c line 2992 in parse_treeish_dataref(const char **p)
there we have a pointer to a struct, which is only assigned inside
the following if/else branches.
Then that place would need to be fixed up to
struct object_entry *e = e;

Regards,
Stefan

On 05/26/2013 10:08 PM, Stefano Lattarini wrote:
> On 05/26/2013 10:05 PM, Stefan Beller wrote:
>> Reported by cppcheck.
>>
>> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
>> ---
>>  fast-import.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fast-import.c b/fast-import.c
>> index 5f539d7..0142e3a 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -2914,7 +2914,7 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20])
>>  static void parse_cat_blob(void)
>>  {
>>  	const char *p;
>> -	struct object_entry *oe = oe;
>>
> This was done on purpose, to avoid spurious warnings with (at least)
> some versions of GCC.
> 
>> +	struct object_entry *oe;
>>  	unsigned char sha1[20];
>>  
>>  	/* cat-blob SP <object> LF */
> 
> Regards,
>   Stefano
> 

```

## Stefano Lattarini, 2013-05-26 20:17

Subject: Re: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <51A26DBD.80106@gmail.com>
URL: https://gitlist.dev/e/51A26DBD.80106%40gmail.com
In-Reply-To: <51A26D0D.2030702@googlemail.com>

```
On 05/26/2013 10:14 PM, Stefan Beller wrote:
> It's not done very often.
>
Of course; it's done only in those places where GCC gave spurious
warnings.  And it's done for no other reason that to silence said
warnings.

> [SNIP] rest of message

Regards,
  Stefano

```

## Stefan Beller, 2013-05-26 20:23

Subject: Re: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <51A26F44.4020406@googlemail.com>
URL: https://gitlist.dev/e/51A26F44.4020406%40googlemail.com
In-Reply-To: <51A26DBD.80106@gmail.com>

```
The line in question was not fixed up, but originally added in
85c6239. However I see your point, it may reintroduce warnings.

Regards,
Stefan

On 05/26/2013 10:17 PM, Stefano Lattarini wrote:
> On 05/26/2013 10:14 PM, Stefan Beller wrote:
>> It's not done very often.
>>
> Of course; it's done only in those places where GCC gave spurious
> warnings.  And it's done for no other reason that to silence said
> warnings.
> 
>> [SNIP] rest of message
> 
> Regards,
>   Stefano
> 

```

## Joachim Schmitz, 2013-05-28 08:22

Subject: Re: [PATCH] fast-import: Remove redundant assignment of 'oe' to itself.
Message-ID: <ko1pfi$7f6$1@ger.gmane.org>
URL: https://gitlist.dev/e/ko1pfi%247f6%241%40ger.gmane.org
In-Reply-To: <51A26BB7.3060702@gmail.com>

```
Stefano Lattarini wrote:
> On 05/26/2013 10:05 PM, Stefan Beller wrote:
>> Reported by cppcheck.
>>
>> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
>> ---
>>  fast-import.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fast-import.c b/fast-import.c
>> index 5f539d7..0142e3a 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -2914,7 +2914,7 @@ static void cat_blob(struct object_entry *oe,
>>  unsigned char sha1[20]) static void parse_cat_blob(void)
>>  {
>>  const char *p;
>> - struct object_entry *oe = oe;
>>
> This was done on purpose, to avoid spurious warnings with (at least)
> some versions of GCC.
>
>> + struct object_entry *oe;
>>  unsigned char sha1[20];
>>
>>  /* cat-blob SP <object> LF */
>

This strange construct has been removed in other places meanwhile. It is 
violating C-standards (C89, C99) and as such causes warnings with other 
compilers, so this is fighting fire with fire. As it is a pointer it may be 
more sensible to initialize with NULL, should appease all compilers and 
still be correct.

Bye, Jojo 

```
