Bug in TIME function
Kaz Kylheku
920-082-4242@kylheku.com
Thu Sep 12 18:44:00 GMT 2019
On 2019-09-12 11:05, tlake@twcny.rr.com wrote:
> The code below returns -1. It shouldn't.
Says who?
I don't see anything in the specification which says that a null pointer
argument is allowed:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/times.html
Passing a null pointer to an ISO C or POSIX library function results in
undefined behavior,
except where it is documented otherwise.
GNU/Linux (specifically the Glibc implementation of libc) also doesn't
document any such extension (being able to pass a null pointer to
times).
So even in light of the goal of Cygwin providing GNU/Linux compatibility
beyond POSIX, there is no justification for supporting times(0).
> #include <sys/times.h>
> #include <stdio.h>
>
> int main(int argc, char *argv[])
>
> {
> printf("return value %ld\n", (long)times((struct tms*)0));
The pointer cast is not required here; you have a prototype of
the times function in scope; the equivalent times(0) will give you
the undefined behavior you're asking for.
> return 0;
> }
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list