threads / patch / 33943

patchfast-import: Remove redundant assignment of 'oe' to itself.

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

## tl;dr

6 messages between May 26, 2013 and May 28, 2013. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Stefan Beller· May 26, 2013, 20:05 UTC · lore
Reported by cppcheck.
Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 fast-import.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to fast-import.c +1 −1
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· May 26, 2013, 20:08 UTC · re: Stefan Beller · lore

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

On 05/26/2013 10:05 PM, Stefan Beller wrote:
Show 17 quoted lines
> 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· May 26, 2013, 20:14 UTC · re: Stefano Lattarini · lore

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

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:
Show 29 quoted lines
> 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· May 26, 2013, 20:17 UTC · re: Stefan Beller · lore

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

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· May 26, 2013, 20:23 UTC · re: Stefano Lattarini · lore

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

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:
Show 12 quoted lines
> 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· May 28, 2013, 08:22 UTC · re: Stefano Lattarini · lore

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

Stefano Lattarini wrote:
Show 26 quoted lines
> 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 

← back to recent threads