Since this module (and gnulib in general) assume time_t is an integer
type and this module already depends on stdckdint-h, we can just use
ckd_add to check for overflows.

-- 8< --

* lib/parse-datetime.y (time_overflow): Use ckd_add to check for
overflow.
---
 ChangeLog            | 6 ++++++
 lib/parse-datetime.y | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 85d0713c16..b1725725ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-02-15  Collin Funk  <[email protected]>
+
+       parse-datetime: Prefer ckd_add to checking overflow by hand.
+       * lib/parse-datetime.y (time_overflow): Use ckd_add to check for
+       overflow.
+
 2026-02-14  Paul Eggert  <[email protected]>
 
        fchownat: port to IBM XL C for AIX 16.1
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index 8d396b1273..6732bf1520 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -99,8 +99,8 @@ static_assert (TYPE_MAXIMUM (time_t) <= INTMAX_MAX);
 static bool
 time_overflow (intmax_t n)
 {
-  return ! ((TYPE_SIGNED (time_t) ? TYPE_MINIMUM (time_t) <= n : 0 <= n)
-            && n <= TYPE_MAXIMUM (time_t));
+  time_t t;
+  return ckd_add (&t, n, 0);
 }
 
 /* Convert a possibly-signed character to an unsigned character.  This is
-- 
2.53.0


Reply via email to