Skip to contentSkip to conversation

Kbuild, lto: Avoid reported warning with strtoul

PATCH In review Andi Kleen 4 participants 6 messages Apr 18, 2014 – Apr 22, 2014 Kbuild

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Kbuild, lto: Avoid reported warning with strtoul

From: Andi Kleen <[email protected]>

Apparently someone's C library declares strtoul with warn_unused_result. Cast to void to avoid the warning. Error handling is not useful here.

---
 scripts/mod/modpost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/modpost.c +1 -1
index 0663556..b9cf439 100644
@@ -1707,7 +1707,7 @@ static char *remove_dot(char *s)
 	int n = strcspn(s, ".");
 
 	if (n > 0 && s[n] != 0) {
-		strtoul(s + n + 1, &end, 10);
+		(void)strtoul(s + n + 1, &end, 10);
 		if  (end > s + n + 1 && (*end == '.' || *end == 0))
 			s[n] = 0;
 	}
Signature · 1 line
1.8.5.2
#1 lore raw
Quoted 4 lines · Andi Kleen

From: Andi Kleen <[email protected]>

Apparently someone's C library declares strtoul with warn_unused_result. Cast to void to avoid the warning. Error handling is not useful here.

Umm... Since we don't give a fsck for the value, isn't that simply

	char *p = strchr(s, '.');
	if (p) {
		size_t m = strspn(p + 1, "0123456789");
		if (m > 0 && (p[m + 1] == '.' || p[m + 1] == '\0'))
			*p = '\0';
	}
#2 lore raw
Quoted 7 lines · Al Viro
Quoted 4 lines · Andi Kleen

From: Andi Kleen <[email protected]>

Apparently someone's C library declares strtoul with warn_unused_result. Cast to void to avoid the warning. Error handling is not useful here.

Umm... Since we don't give a fsck for the value, isn't that simply

Yes your code is equivalent to mine.

-Andi

#3 lore raw
In reply to Andi Kleen
Quoted 4 lines · Andi Kleen

From: Andi Kleen <[email protected]>

Apparently someone's C library declares strtoul with warn_unused_result. Cast to void to avoid the warning. Error handling is not useful here.

I just did a x86_64 compilation without a CROSS_COMPILE= option (My .config also had a empty string) and so gcc must be used for it?

$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Quoted 11 lines
---
 scripts/mod/modpost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/modpost.c +0 -0
index 0663556..b9cf439 100644

scripts/mod/modpost.c static char *remove_dot(char *s) · line 1710

Quoted 5 lines
scripts/mod/modpost.c +1 -1
@@ -1707,7 +1707,7 @@ static char *remove_dot(char *s)
        int n = strcspn(s, ".");
 
        if (n > 0 && s[n] != 0) {
-               strtoul(s + n + 1, &end, 10);
+               (void)strtoul(s + n + 1, &end, 10);

I tried this earlier before reporting and it still had the same problem :( I tried it again just to cross check and still getting this:

scripts/mod/modpost.c: In function ‘remove_dot’:
scripts/mod/modpost.c:1710:3: warning: ignoring return value of ‘strtoul’, declared with attribute warn_unused_result [-Wunused-result]

#4 lore raw
Quoted 12 lines · Viresh Kumar

scripts/mod/modpost.c static char *remove_dot(char *s) · line 1710

Quoted 8 lines
scripts/mod/modpost.c +1 -1
@@ -1707,7 +1707,7 @@ static char *remove_dot(char *s)
        int n = strcspn(s, ".");
 
        if (n > 0 && s[n] != 0) {
-               strtoul(s + n + 1, &end, 10);
+               (void)strtoul(s + n + 1, &end, 10);

I tried this earlier before reporting and it still had the same problem :( I tried it again just to cross check and still getting this:

Quoted 4 lines

scripts/mod/modpost.c: In function ‘remove_dot’:
scripts/mod/modpost.c:1710:3: warning: ignoring return value of ‘strtoul’, declared with attribute warn_unused_result [-Wunused-result]

Hmm that's odd. I guess could assign it to a dummy variable or use viro's variant.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#5 lore raw
Quoted 1 line · Andi Kleen

Hmm that's odd. I guess could assign it to a dummy variable

That produces this:

scripts/mod/modpost.c: In function ‘remove_dot’:
scripts/mod/modpost.c:1708:16: warning: variable ‘ignore’ set but not used [-Wunused-but-set-variable]

Quoted 1 line

or use viro's variant.

It looks fine but can't test if works exactly the same way as current implementation.