This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in TIME function


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]