Skip to content

Commit 18ca9b9

Browse files
Dan Gohmanjohn-sharratt
authored andcommitted
Fix gettimeofday to correctly handle a null argument.
`gettimeofday` is defined to do nothing if passed NULL.
1 parent 1d787dc commit 18ca9b9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#include <wasi/api.h>
1010

1111
int gettimeofday(struct timeval *restrict tp, void *tz) {
12-
__wasi_timestamp_t ts = 0;
13-
(void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
14-
*tp = timestamp_to_timeval(ts);
12+
if (tp != NULL) {
13+
__wasi_timestamp_t ts = 0;
14+
(void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
15+
*tp = timestamp_to_timeval(ts);
16+
}
1517
return 0;
1618
}

0 commit comments

Comments
 (0)