This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/16437] [x86_64] struct timespec definition is non-conforming on x32 and perhaps other archs
- From: "hjl.tools at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 11 Feb 2015 18:30:30 +0000
- Subject: [Bug libc/16437] [x86_64] struct timespec definition is non-conforming on x32 and perhaps other archs
- Auto-submitted: auto-generated
- References: <bug-16437-131 at http dot sourceware dot org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=16437
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |hjl.tools at gmail dot com
Resolution|--- |WONTFIX
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Rich Felker from comment #0)
> glibc's definition of struct timespec is wrong: it's using __syscall_slong_t
> rather than long. This violates the requirements of both POSIX and C11. See
> C11 7.27.1 Components of time, paragraph 4:
>
> "The range and precision of times representable in clock_t and time_t are
> implementation-defined. The timespec structure shall contain at least the
> following members, in any order.
>
> time_t tv_sec; // whole seconds -- >= 0
> long tv_nsec; // nanoseconds -- [0, 999999999]"
>
> This breaks conforming code such as:
>
> struct timespec ts;
> sscanf("42", "%ld", &ts.tv_nsec);
>
Both clang and GCC will complain:
[hjl@gnu-6 tmp]$ cat t.c
#include <stdio.h>
#include <sys/time.h>
long
foo (const char *str)
{
struct timespec ts;
sscanf(str, "%ld", &ts.tv_nsec);
return ts.tv_nsec;
}
[hjl@gnu-6 tmp]$ /opt/llvm/x32/bin/clang -c -mx32 t.c
t.c:8:22: warning: format specifies type 'long *' but the argument has type
'__syscall_slong_t *' (aka 'long long *') [-Wformat]
sscanf(str, "%ld", &ts.tv_nsec);
~~~ ^~~~~~~~~~~
%lld
1 warning generated.
[hjl@gnu-6 tmp]$ gcc -Wall -c -mx32 t.c
t.c: In function âfooâ:
t.c:8:3: warning: format â%ldâ expects argument of type âlong int *â, but
argument 3 has type â__syscall_slong_t *â [-Wformat=]
sscanf(str, "%ld", &ts.tv_nsec);
^
[hjl@gnu-6 tmp]$
This issue has been discussed in March, 2012:
https://sourceware.org/ml/libc-alpha/2012-03/msg00438.html
I won't change x32. I consider this issue is closed.
--
You are receiving this mail because:
You are on the CC list for the bug.