Skip to content

Commit bf52585

Browse files
tagunilfabiobaltieri
authored andcommitted
posix: clock: fix 32-bit time_t overflow in __z_clock_nanosleep
Nanosecond time calculation overflows if the libc has 32-bit time_t. One such libc is the classic ARC MWDT one, but there might be others. Signed-off-by: Ilya Tagunov <[email protected]>
1 parent 760210f commit bf52585

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/posix/options/clock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int __z_clock_nanosleep(clockid_t clock_id, int flags, const struct times
222222
ns = rqtp->tv_nsec + NSEC_PER_SEC
223223
+ k_sleep(K_SECONDS(rqtp->tv_sec - 1)) * NSEC_PER_MSEC;
224224
} else {
225-
ns = rqtp->tv_sec * NSEC_PER_SEC + rqtp->tv_nsec;
225+
ns = (uint64_t)rqtp->tv_sec * NSEC_PER_SEC + rqtp->tv_nsec;
226226
}
227227

228228
uptime_ns = k_ticks_to_ns_ceil64(sys_clock_tick_get());

0 commit comments

Comments
 (0)