On 06/14/14 14:37, Bruce Korb wrote:
On 06/11/14 15:46, Jim Meyering wrote:
I wrote the patch, and tested by running this:

   ./gnulib-tool --create-testdir --dir=/tmp/x --with-tests --test 
parse-duration

Excellent.  Please push it, thank you!

Actually, it occurs to me that the result still uses TIME_MAX and, if not 
guarded,
still conflicts with glibc's claim to a new name.  I still think that 
"implementations"
need an unambiguously distinct name space.  *_MAX is too greedy.
diff --git a/ChangeLog b/ChangeLog
index 6fff9d7..4711a03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-06-11  Bruce Korb  <bk...@gnu.org>
+	Jim Meyering  <address@hidden>
+
+	parse-duration: eliminate 68 year duration limit
+	* lib/parse-duration.c: Include "intprops.h".
+	(TIME_MAX): rename to MAX_DURATION and define to
+	TYPE_MAXIMUM(time_t).
+	* modules/parse-duration (Depends-on): Add intprops.
+	Reported by Jonas 'Sortie' Termansen.
+
 2014-06-14  Paul Eggert  <egg...@cs.ucla.edu>
 
 	pthread: don't assume AC_CANONICAL_HOST, port better to Solaris, etc.
diff --git a/lib/parse-duration.c b/lib/parse-duration.c
index 037e81e..82a1193 100644
--- a/lib/parse-duration.c
+++ b/lib/parse-duration.c
@@ -27,6 +27,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "intprops.h"
+
 #ifndef NUL
 #define NUL '\0'
 #endif
@@ -51,7 +53,8 @@ typedef enum {
 #define SEC_PER_MONTH   (SEC_PER_DAY * 30)
 #define SEC_PER_YEAR    (SEC_PER_DAY * 365)
 
-#define TIME_MAX        0x7FFFFFFF
+#undef  MAX_DURATION
+#define MAX_DURATION    TYPE_MAXIMUM(time_t)
 
 /* Wrapper around strtoul that does not require a cast.  */
 static unsigned long
@@ -80,14 +83,14 @@ scale_n_add (time_t base, time_t val, int scale)
       return BAD_TIME;
     }
 
-  if (val > TIME_MAX / scale)
+  if (val > MAX_DURATION / scale)
     {
       errno = ERANGE;
       return BAD_TIME;
     }
 
   val *= scale;
-  if (base > TIME_MAX - val)
+  if (base > MAX_DURATION - val)
     {
       errno = ERANGE;
       return BAD_TIME;
diff --git a/modules/parse-duration b/modules/parse-duration
index 46288c0..6184dc4 100644
--- a/modules/parse-duration
+++ b/modules/parse-duration
@@ -6,6 +6,7 @@ lib/parse-duration.h
 lib/parse-duration.c
 
 Depends-on:
+intprops
 
 configure.ac:
 

Reply via email to