Skip to content

Commit 30094b6

Browse files
committedJun 1, 2022
Fix gettimeofday to correctly handle a null argument.
`gettimeofday` is defined to do nothing if passed NULL.
1 parent d8d00bc commit 30094b6

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

+5-3
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)
Please sign in to comment.