This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/13970] New: strtol, strtoll, etc should not be declared with warn_unused_result
- From: "eggert at gnu dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Wed, 11 Apr 2012 21:06:09 +0000
- Subject: [Bug libc/13970] New: strtol, strtoll, etc should not be declared with warn_unused_result
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=13970
Bug #: 13970
Summary: strtol, strtoll, etc should not be declared with
warn_unused_result
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: unassigned@sourceware.org
ReportedBy: eggert@gnu.org
CC: drepper.fsp@gmail.com
Classification: Unclassified
Created attachment 6336
--> http://sourceware.org/bugzilla/attachment.cgi?id=6336
Patch to remove __wur from strtol etc.
I ran into the following problem when developing some real code for
the GNU core utilities.
The following example code provides two reasonable ways to return the length
of the leading numeric part of a string:
/* Return the length of the leading numeric part of the string S,
or 0 if S does not start with a number. */
#include <stdlib.h>
size_t
numlen (char const *s)
{
char *endptr;
strtoll (s, &endptr, 10);
return endptr - s;
}
/* Likewise, but use strtoimax. */
#include <inttypes.h>
size_t
numlen_imax (char const *s)
{
char *endptr;
strtoimax (s, &endptr, 10);
return endptr - s;
}
However, compiling this with the GNU C library returns a diagnostic
for strtoll.
$ gcc -S -D_FORTIFY_SOURCE=2 -O2 use-strtol.c
use-strtol.c: In function 'numlen':
use-strtol.c:8:11: warning: ignoring return value of 'strtoll', declared
with attribute warn_unused_result [-Wunused-result]
As can be seen, strtoimax does not have the problem.
glibc should not warn about unused results of strtol, etc., because
these are not security problems and are not always bugs, as the above
useful example illustrates.
I'm attaching the obvious patch, in "git format-patch" format.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.