BUG: gettimeofday() didn't handle first argument being NULL

109224573 109224573@qq.com
Tue Feb 20 11:15:34 GMT 2024

this code works on Linux, but not msys2:

#include<sys time.h="">
int main() {
    struct timezone tz;
    gettimeofday(NULL, &tz);

I guess the reason would be

extern "C" int
gettimeofday (struct timeval *__restrict tv, void *__restrict tzvp)
  struct timezone *tz = (struct timezone *) tzvp;
  static bool tzflag;
  LONGLONG now = get_clock (CLOCK_REALTIME)->usecs ();

  tv->tv_sec = now / USPERSEC;
  tv->tv_usec = now % USPERSEC;

If so, the fix should be add if (tv != NULL)

I found this issue due to https://github.com/redis/redis/issues/12719</sys></stdio.h>

More information about the Cygwin mailing list