On 10/3/22 12:56, Paul Eggert wrote:
In looking through old dev histories it appears Paul pushes changes every now and then, so I'll wait until he's pushed his next batch of changes, which will presumably include some timestamp-related fixes, before looking into this again.

Thanks, that merge looks good to me.

I might also suggest installing the attached, which contains code that won't be executed on any platform that I know about, but which is needed to avoid undefined behavior on platforms where INT_MAX == INTMAX_MAX (maybe a signal-processing CPU? :-). This is to document the assumption that INT_MAX < INTMAX_MAX, not to fix any real bug on any platform I know about. Of course this is low priority.
From 81c5f5de755911f3a24900886d57a7b0dbd0178b Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 4 Oct 2022 15:38:14 -0700
Subject: [PATCH] Fix theoretical bug when int == intmax_t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/file.c (file_timestamp_sprintf):
Port to platforms where int == intmax_t.  I don’t know of any such
platforms, so to some extent this patch merely documents the
assumption that INT_MAX < INTMAX_MAX.
---
 src/file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/file.c b/src/file.c
index 62b8dd00..b0b24cc9 100644
--- a/src/file.c
+++ b/src/file.c
@@ -1019,10 +1019,15 @@ file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
 
   if (tm)
     {
+#if defined INTMAX_MAX && INTMAX_MAX - 1900 < INT_MAX
+      /* A theoretical host where (intmax_t) INT_MAX + 1900 overflows.  */
+      strftime (p, FILE_TIMESTAMP_PRINT_LEN_BOUND + 1, "%Y-%m-%d %H:%M:%S", tm);
+#else
       intmax_t year = tm->tm_year;
       sprintf (p, "%04" PRIdMAX "-%02d-%02d %02d:%02d:%02d",
                year + 1900, tm->tm_mon + 1, tm->tm_mday,
                tm->tm_hour, tm->tm_min, tm->tm_sec);
+#endif
     }
   else if (t < 0)
     sprintf (p, "%" PRIdMAX, (intmax_t) t);
-- 
2.37.3

Reply via email to