Skip to content

Commit 93f71d7

Browse files
Gary-HobsonGUIDINGLI
authored andcommitted
time: fix 32-bit integer truncation warning
CID 1266677: (#2 of 2): Use 32-bit time_t (Y2K38_SAFETY) 1. declaration_with_small_time_t: Declare use of time_t, which is defined as 32 bits wide on this platform, while the minimum safe width is 64. Signed-off-by: yinshengkai <yinshengkai@xiaomi.com> Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent f718603 commit 93f71d7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/nuttx/clock.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ EXTERN volatile clock_t g_system_ticks;
333333
#define clock_ticks2time(ts, tick) \
334334
do \
335335
{ \
336-
clock_t _tick = (tick); \
337-
(ts)->tv_sec = div_const(_tick, TICK_PER_SEC); \
336+
clock_t _tick = (clock_t)(tick); \
337+
(ts)->tv_sec = (time_t)div_const(_tick, TICK_PER_SEC); \
338338
_tick -= (clock_t)(ts)->tv_sec * TICK_PER_SEC; \
339-
(ts)->tv_nsec = _tick * NSEC_PER_TICK; \
339+
(ts)->tv_nsec = (long)_tick * NSEC_PER_TICK; \
340340
} \
341341
while (0)
342342

@@ -347,9 +347,9 @@ EXTERN volatile clock_t g_system_ticks;
347347
do \
348348
{ \
349349
uint64_t _usec = (usec); \
350-
(ts)->tv_sec = div_const(_usec, USEC_PER_SEC); \
350+
(ts)->tv_sec = (time_t)div_const(_usec, USEC_PER_SEC); \
351351
_usec -= (uint64_t)(ts)->tv_sec * USEC_PER_SEC; \
352-
(ts)->tv_nsec = _usec * NSEC_PER_USEC; \
352+
(ts)->tv_nsec = (long)_usec * NSEC_PER_USEC; \
353353
} \
354354
while (0)
355355

@@ -360,9 +360,9 @@ EXTERN volatile clock_t g_system_ticks;
360360
do \
361361
{ \
362362
uint64_t _nsec = (nsec); \
363-
(ts)->tv_sec = div_const(_nsec, NSEC_PER_SEC); \
363+
(ts)->tv_sec = (time_t)div_const(_nsec, NSEC_PER_SEC); \
364364
_nsec -= (uint64_t)(ts)->tv_sec * NSEC_PER_SEC; \
365-
(ts)->tv_nsec = _nsec; \
365+
(ts)->tv_nsec = (long)_nsec; \
366366
} \
367367
while (0)
368368

0 commit comments

Comments
 (0)