# [PATCH] fast-import.c: Silence build warning

9 messages from 2009-08-31 to 2009-09-01. Participants: Michael Wookey, Sverre Rabbelier, Alex Riesen, Junio C Hamano, Stephen Boyd.
Thread: https://gitlist.dev/t/20799

## Michael Wookey, 2009-08-31 11:21

Subject: [PATCH] fast-import.c: Silence build warning
Message-ID: <d2e97e800908310421u7de8ae58o361bd64a026384bf@mail.gmail.com>
URL: https://gitlist.dev/e/d2e97e800908310421u7de8ae58o361bd64a026384bf%40mail.gmail.com

```
gcc 4.3.3 (Ubuntu 9.04) warns that the return value of strtoul() was not
checked by issuing the following notice:

  warning: ignoring return value of ‘strtoul’, declared with attribute
warn_unused_result

Provide a dummy variable to keep the compiler happy.

Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
---
 fast-import.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 7ef9865..1386e75 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1744,10 +1744,11 @@ static int validate_raw_date(const char *src,
char *result, int maxlen)
 {
 	const char *orig_src = src;
 	char *endp;
+	unsigned long int unused;

 	errno = 0;

-	strtoul(src, &endp, 10);
+	unused = strtoul(src, &endp, 10);
 	if (errno || endp == src || *endp != ' ')
 		return -1;

@@ -1755,7 +1756,7 @@ static int validate_raw_date(const char *src,
char *result, int maxlen)
 	if (*src != '-' && *src != '+')
 		return -1;

-	strtoul(src + 1, &endp, 10);
+	unused = strtoul(src + 1, &endp, 10);
 	if (errno || endp == src || *endp || (endp - orig_src) >= maxlen)
 		return -1;

-- 
1.6.4.2.236.gf324c

```

## Sverre Rabbelier, 2009-08-31 12:29

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <fabb9a1e0908310529q4c601a73t671cc2813dfdb1a3@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0908310529q4c601a73t671cc2813dfdb1a3%40mail.gmail.com
In-Reply-To: <d2e97e800908310421u7de8ae58o361bd64a026384bf@mail.gmail.com>

```
Heya,

On Mon, Aug 31, 2009 at 04:21, Michael Wookey<michaelwookey@gmail.com> wrote:
> Provide a dummy variable to keep the compiler happy.

Should we not instead check the value?

-- 
Cheers,

Sverre Rabbelier

```

## Alex Riesen, 2009-08-31 21:27

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <81b0412b0908311427t5b4a24ffg1d7d272669476117@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0908311427t5b4a24ffg1d7d272669476117%40mail.gmail.com
In-Reply-To: <fabb9a1e0908310529q4c601a73t671cc2813dfdb1a3@mail.gmail.com>

```
On Mon, Aug 31, 2009 at 14:29, Sverre Rabbelier<srabbelier@gmail.com> wrote:
> On Mon, Aug 31, 2009 at 04:21, Michael Wookey<michaelwookey@gmail.com> wrote:
>> Provide a dummy variable to keep the compiler happy.
>
> Should we not instead check the value?

Why? It is endp (end of the parsed number) we're interested in.

```

## Sverre Rabbelier, 2009-08-31 21:42

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <fabb9a1e0908311442q2a56b1cft8ad7fe75bfde38c3@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0908311442q2a56b1cft8ad7fe75bfde38c3%40mail.gmail.com
In-Reply-To: <81b0412b0908311427t5b4a24ffg1d7d272669476117@mail.gmail.com>

```
Heya,

On Mon, Aug 31, 2009 at 23:27, Alex Riesen<raa.lkml@gmail.com> wrote:
> Why? It is endp (end of the parsed number) we're interested in.

Ah, my bad, I hadn't checked stroul's signature, sorry for the noise.

-- 
Cheers,

Sverre Rabbelier

```

## Michael Wookey, 2009-08-31 23:31

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <d2e97e800908311631x6fdd7781v2e893d1ca62378b6@mail.gmail.com>
URL: https://gitlist.dev/e/d2e97e800908311631x6fdd7781v2e893d1ca62378b6%40mail.gmail.com
In-Reply-To: <81b0412b0908311427t5b4a24ffg1d7d272669476117@mail.gmail.com>

```
2009/9/1 Alex Riesen <raa.lkml@gmail.com>:
> On Mon, Aug 31, 2009 at 14:29, Sverre Rabbelier<srabbelier@gmail.com> wrote:
>> On Mon, Aug 31, 2009 at 04:21, Michael Wookey<michaelwookey@gmail.com> wrote:
>>> Provide a dummy variable to keep the compiler happy.
>>
>> Should we not instead check the value?
>
> Why? It is endp (end of the parsed number) we're interested in.

Good point, perhaps the commit message should mention why we don't
bother checking the return value. Something like this maybe?

-- >8 --
gcc 4.3.3 (Ubuntu 9.04) warns that the return value of strtoul() was not
checked by issuing the following notice:

 warning: ignoring return value of ‘strtoul’, declared with attribute
warn_unused_result

The return value of strtoul() isn't used because we are only interested
in what is placed into endp.  As such, provide a dummy variable to keep
the compiler happy.

Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
-- >8 --

```

## Junio C Hamano, 2009-08-31 23:42

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <7vfxb7y2h3.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfxb7y2h3.fsf%40alter.siamese.dyndns.org
In-Reply-To: <d2e97e800908310421u7de8ae58o361bd64a026384bf@mail.gmail.com>

```
Michael Wookey <michaelwookey@gmail.com> writes:

> gcc 4.3.3 (Ubuntu 9.04) warns that the return value of strtoul() was not
> checked by issuing the following notice:
>
>   warning: ignoring return value of ‘strtoul’, declared with attribute
> warn_unused_result
>
> Provide a dummy variable to keep the compiler happy.
>
> Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
> ---
>  fast-import.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fast-import.c b/fast-import.c
> index 7ef9865..1386e75 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -1744,10 +1744,11 @@ static int validate_raw_date(const char *src,
> char *result, int maxlen)
>  {
>  	const char *orig_src = src;
>  	char *endp;
> +	unsigned long int unused;
>
>  	errno = 0;
>
> -	strtoul(src, &endp, 10);
> +	unused = strtoul(src, &endp, 10);

Isn't this typically done by casting the expression to (void)?

Otherwise a clever compiler has every right to complain "the variable
unused is assigned but never used."

```

## Michael Wookey, 2009-08-31 23:55

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <d2e97e800908311655t553d6c4bo6ed45fe37819c1d8@mail.gmail.com>
URL: https://gitlist.dev/e/d2e97e800908311655t553d6c4bo6ed45fe37819c1d8%40mail.gmail.com
In-Reply-To: <7vfxb7y2h3.fsf@alter.siamese.dyndns.org>

```
2009/9/1 Junio C Hamano <gitster@pobox.com>:
> Michael Wookey <michaelwookey@gmail.com> writes:
>
>> gcc 4.3.3 (Ubuntu 9.04) warns that the return value of strtoul() was not
>> checked by issuing the following notice:
>>
>>   warning: ignoring return value of ‘strtoul’, declared with attribute
>> warn_unused_result
>>
>> Provide a dummy variable to keep the compiler happy.
>>
>> Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
>> ---
>>  fast-import.c |    5 +++--
>>  1 files changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/fast-import.c b/fast-import.c
>> index 7ef9865..1386e75 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -1744,10 +1744,11 @@ static int validate_raw_date(const char *src,
>> char *result, int maxlen)
>>  {
>>       const char *orig_src = src;
>>       char *endp;
>> +     unsigned long int unused;
>>
>>       errno = 0;
>>
>> -     strtoul(src, &endp, 10);
>> +     unused = strtoul(src, &endp, 10);
>
> Isn't this typically done by casting the expression to (void)?

I originally tried that - the compiler still complains.

> Otherwise a clever compiler has every right to complain "the variable
> unused is assigned but never used."

 I get no other warnings, so does that make gcc less than clever? ;-)

```

## Stephen Boyd, 2009-09-01 04:06

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <4A9C9DB4.8070702@gmail.com>
URL: https://gitlist.dev/e/4A9C9DB4.8070702%40gmail.com
In-Reply-To: <d2e97e800908311655t553d6c4bo6ed45fe37819c1d8@mail.gmail.com>

```
Michael Wookey wrote:
> 2009/9/1 Junio C Hamano <gitster@pobox.com>:
>> Isn't this typically done by casting the expression to (void)?
>
> I originally tried that - the compiler still complains.
>
>> Otherwise a clever compiler has every right to complain "the variable
>> unused is assigned but never used.
>
> I get no other warnings, so does that make gcc less than clever?  ;-) 

I noticed this warning recently too when I upgraded my box and a flurry
of fwrite() unused warnings came up. Looks like ubuntu patches that
issue[1] by arguing it's a valid programming style to
fwrite/fflush/ferror. Perhaps this programming style could follow a
similar reasoning?

It gets better though. Commit c55fae4 (fast-import.c: stricter strtoul
check, silence compiler warning, 2008-12-21) made this change already.
Then commit eb3a9dd (Remove unused function scope local variables,
2009-03-07) came by and removed it. Unless the definition of strtoul
drops the attribute I fear we'll keep going back and forth.

-- Footnotes --
[1] https://lists.ubuntu.com/archives/ubuntu-devel/2009-March/027832.html

```

## Alex Riesen, 2009-09-01 06:30

Subject: Re: [PATCH] fast-import.c: Silence build warning
Message-ID: <81b0412b0908312330t3135d033o14a6cb73797edf18@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0908312330t3135d033o14a6cb73797edf18%40mail.gmail.com
In-Reply-To: <d2e97e800908311655t553d6c4bo6ed45fe37819c1d8@mail.gmail.com>

```
On Tue, Sep 1, 2009 at 01:55, Michael Wookey<michaelwookey@gmail.com> wrote:
>> Otherwise a clever compiler has every right to complain "the variable
>> unused is assigned but never used."
>
>  I get no other warnings, so does that make gcc less than clever? ;-)

It only does what it is instructed to do: the function is annotated with
warn_unused_result attribute. What really is annoying is someones
choice of the functions to annotate.

```
