Skip to content

Commit d3ec916

Browse files
cfriedtkartben
authored andcommitted
sys: timeutil: check for 32-bit time_t to avoid warning (part 2)
Same error had to be fixed in the branch where optimizations were done. This is probably a good example of where using `if (IS_ENABLED()) ...` is a better choice than using `#ifdef`. Because the compiler would have caught this error last time as well. Anyway, same problem - different line(s)! A warning was propogated to error when building for native_sim/native. ``` timeutil.h:682:17: error: result of comparison of constant \ -9223372036854775808 with expression of type '__time_t' (aka 'long') \ is always false [-Werror,-Wtautological-constant-out-of-range-compare] timeutil.h:680:17: error: result of comparison of constant \ -9223372036854775808 with expression of type '__time_t' (aka 'long') \ is always false [-Werror,-Wtautological-constant-out-of-range-compare] ``` This is due to the issue described in #90029. Add workarounds for `timespec_to_timeout()` and `timespec_negate()` until 90029 is resolved. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent 4dea09d commit d3ec916

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/zephyr/sys/timeutil.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,16 @@ static inline k_timeout_t timespec_to_timeout(const struct timespec *ts)
677677
#if defined(CONFIG_SPEED_OPTIMIZATIONS)
678678

679679
return (k_timeout_t){
680-
.ticks = ((ts->tv_sec == INT64_MAX) && (ts->tv_nsec == NSEC_PER_SEC - 1)) *
680+
/* note: must check for 32-bit size here until #90029 is resolved */
681+
.ticks = ((sizeof(ts->tv_sec) == sizeof(int32_t) && (ts->tv_sec == INT32_MAX) &&
682+
(ts->tv_nsec == NSEC_PER_SEC - 1)) ||
683+
((sizeof(ts->tv_sec) == sizeof(int64_t)) && (ts->tv_sec == INT64_MAX) &&
684+
(ts->tv_nsec == NSEC_PER_SEC - 1))) *
681685
K_TICKS_FOREVER +
682-
((ts->tv_sec != INT64_MAX) && (ts->tv_sec >= 0)) *
686+
((sizeof(ts->tv_sec) == sizeof(int32_t) && (ts->tv_sec == INT32_MAX) &&
687+
(ts->tv_nsec == NSEC_PER_SEC - 1)) ||
688+
((sizeof(ts->tv_sec) == sizeof(int64_t)) && (ts->tv_sec != INT64_MAX) &&
689+
(ts->tv_sec >= 0))) *
683690
(IS_ENABLED(CONFIG_TIMEOUT_64BIT)
684691
? (int64_t)(CLAMP(
685692
k_sec_to_ticks_floor64(ts->tv_sec) +

0 commit comments

Comments
 (0)