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

Subsystems: the rest

DORMANTno replies

9 messages, 5 authors, 2016-06-15 · open the first message on its own page

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

From: Michael Wookey <hidden>
Date: 2016-06-15 22:47:20

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

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

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:47:20

Heya,

On Mon, Aug 31, 2009 at 04:21, Michael Wookey[off-list ref] wrote:
Provide a dummy variable to keep the compiler happy.
Should we not instead check the value?

-- 
Cheers,

Sverre Rabbelier

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

From: Alex Riesen <hidden>
Date: 2016-06-15 22:47:20

On Mon, Aug 31, 2009 at 14:29, Sverre Rabbelier[off-list ref] wrote:
On Mon, Aug 31, 2009 at 04:21, Michael Wookey[off-list ref] wrote:
quoted
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.

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

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:47:20

Heya,

On Mon, Aug 31, 2009 at 23:27, Alex Riesen[off-list ref] 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

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

From: Michael Wookey <hidden>
Date: 2016-06-15 22:47:20

2009/9/1 Alex Riesen [off-list ref]:
On Mon, Aug 31, 2009 at 14:29, Sverre Rabbelier[off-list ref] wrote:
quoted
On Mon, Aug 31, 2009 at 04:21, Michael Wookey[off-list ref] wrote:
quoted
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 <redacted>
-- >8 --

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:20

Michael Wookey [off-list ref] writes:
quoted hunk
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 <redacted>
---
 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."

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

From: Michael Wookey <hidden>
Date: 2016-06-15 22:47:20

2009/9/1 Junio C Hamano [off-list ref]:
Michael Wookey [off-list ref] writes:
quoted
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 <redacted>
---
 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? ;-)

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

From: Stephen Boyd <hidden>
Date: 2016-06-15 22:47:20

Michael Wookey wrote:
2009/9/1 Junio C Hamano [off-list ref]:
quoted
Isn't this typically done by casting the expression to (void)?
I originally tried that - the compiler still complains.
quoted
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

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

From: Alex Riesen <hidden>
Date: 2016-06-15 22:47:20

On Tue, Sep 1, 2009 at 01:55, Michael Wookey[off-list ref] wrote:
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help