* Makefile (GCC_DEBUG_FLAGS): Add -Wno-type-limits, which is needed again even with GCC 14, due to the following change. * asctime.c (asctime_r): On platforms where INT_MAX < LONG_MAX, help the compiler optimize away a runtime check, and to optimize away the need to have two static calls to snprintf. --- Makefile | 2 +- asctime.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index e8574551..5473dedd 100644 --- a/Makefile +++ b/Makefile @@ -337,7 +337,7 @@ GCC_DEBUG_FLAGS = -DGCC_LINT -g3 -O3 \ -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure \ -Wtrampolines -Wundef -Wunused-macros -Wuse-after-free=3 \ -Wvariadic-macros -Wvla -Wwrite-strings \ - -Wno-format-nonliteral -Wno-sign-compare + -Wno-format-nonliteral -Wno-sign-compare -Wno-type-limits # # If your system has a "GMT offset" field in its "struct tm"s # (or if you decide to add such a field in your system's "time.h" file), diff --git a/asctime.c b/asctime.c index b4424de4..3817182e 100644 --- a/asctime.c +++ b/asctime.c @@ -85,6 +85,7 @@ asctime_r(struct tm const *restrict timeptr, char *restrict buf) register const char * wn; register const char * mn; int year, mday, hour, min, sec; + long long_TM_YEAR_BASE = TM_YEAR_BASE; size_t bufsize = ((buf == buf_ctime || (!SUPPORT_C89 && buf == buf_asctime)) ? sizeof buf_asctime : STD_ASCTIME_BUF_SIZE); @@ -122,14 +123,14 @@ asctime_r(struct tm const *restrict timeptr, char *restrict buf) Also, avoid overflow when formatting tm_year + TM_YEAR_BASE. */ - if ((year <= INT_MAX - TM_YEAR_BASE + if ((year <= LONG_MAX - TM_YEAR_BASE ? snprintf (buf, bufsize, ((-999 - TM_YEAR_BASE <= year && year <= 9999 - TM_YEAR_BASE) - ? "%s %s%3d %.2d:%.2d:%.2d %04d\n" - : "%s %s%3d %.2d:%.2d:%.2d %d\n"), + ? "%s %s%3d %.2d:%.2d:%.2d %04ld\n" + : "%s %s%3d %.2d:%.2d:%.2d %ld\n"), wn, mn, mday, hour, min, sec, - year + TM_YEAR_BASE) + year + long_TM_YEAR_BASE) : snprintf (buf, bufsize, "%s %s%3d %.2d:%.2d:%.2d %d%d\n", wn, mn, mday, hour, min, sec, -- 2.43.0