@@ -416,24 +416,24 @@ EXTERN volatile clock_t g_system_ticks;
416416 ****************************************************************************/
417417
418418#define clock_timespec_subtract (ts1 , ts2 , ts3 ) \
419- do \
419+ do \
420+ { \
421+ time_t _sec = (ts1)->tv_sec - (ts2)->tv_sec; \
422+ long _nsec = (ts1)->tv_nsec - (ts2)->tv_nsec; \
423+ if (_nsec < 0) \
420424 { \
421- time_t _sec = (ts1)->tv_sec - (ts2)->tv_sec; \
422- long _nsec = (ts1)->tv_nsec - (ts2)->tv_nsec; \
423- if (_nsec < 0) \
424- { \
425- _nsec += NSEC_PER_SEC; \
426- _sec--; \
427- } \
428- if (_sec < 0) \
429- { \
430- _sec = 0; \
431- _nsec = 0; \
432- } \
433- (ts3)->tv_sec = _sec; \
434- (ts3)->tv_nsec = _nsec; \
435- }\
436- while (0)
425+ _nsec += NSEC_PER_SEC; \
426+ _sec--; \
427+ } \
428+ if ((int64_t)_sec < 0) \
429+ { \
430+ _sec = 0; \
431+ _nsec = 0; \
432+ } \
433+ (ts3)->tv_sec = _sec; \
434+ (ts3)->tv_nsec = _nsec; \
435+ }\
436+ while (0)
437437
438438/****************************************************************************
439439 * Name: clock_timespec_compare
@@ -446,9 +446,9 @@ EXTERN volatile clock_t g_system_ticks;
446446 ****************************************************************************/
447447
448448#define clock_timespec_compare (ts1 , ts2 ) \
449- (((ts1)->tv_sec < (ts2)->tv_sec) ? -1 : \
450- ((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \
451- (ts1)->tv_nsec - (ts2)->tv_nsec)
449+ (((ts1)->tv_sec < (ts2)->tv_sec) ? -1 : \
450+ ((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \
451+ (ts1)->tv_nsec - (ts2)->tv_nsec)
452452
453453/****************************************************************************
454454 * Name: clock_abstime2ticks
0 commit comments