]> git.proxmox.com Git - wasi-libc.git/commitdiff
Fix `gettimeofday` to correctly handle a null argument.
authorDan Gohman <dev@sunfishcode.online>
Wed, 25 May 2022 03:55:41 +0000 (20:55 -0700)
committerDan Gohman <dev@sunfishcode.online>
Wed, 1 Jun 2022 18:05:04 +0000 (11:05 -0700)
`gettimeofday` is defined to do nothing if passed NULL.

libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c

index d58cbb9d217ccedd553b4228f91ca9a56e81146a..596bdfff28e2c769b64c3ac4a89a3e9a72992e4e 100644 (file)
@@ -9,8 +9,10 @@
 #include <wasi/api.h>
 
 int gettimeofday(struct timeval *restrict tp, void *tz) {
-  __wasi_timestamp_t ts = 0;
-  (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
-  *tp = timestamp_to_timeval(ts);
+  if (tp != NULL) {
+    __wasi_timestamp_t ts = 0;
+    (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
+    *tp = timestamp_to_timeval(ts);
+  }
   return 0;
 }