]> Savannah Git Hosting - gnulib.git/commitdiff
parse-duration: eliminate 68-year duration limit
authorJim Meyering <meyering@fb.com>
Tue, 17 Jun 2014 15:29:46 +0000 (08:29 -0700)
committerJim Meyering <meyering@fb.com>
Tue, 17 Jun 2014 15:31:37 +0000 (08:31 -0700)
* 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.

ChangeLog
lib/parse-duration.c
modules/parse-duration

index 6fff9d785deb3d21641c96fcda971a4edc517428..5dd0d6f64c43c1aa7a730ac66bdf711fcb11cbed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-06-11  Bruce Korb  <bkorb@gnu.org>
+       Jim Meyering  <meyering@fb.com>
+
+       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  <eggert@cs.ucla.edu>
 
        pthread: don't assume AC_CANONICAL_HOST, port better to Solaris, etc.
index 037e81e412979b4242d9c0a1876e871727b7d529..82a11938eed1d56bf050dfd783eb99f70bb52e59 100644 (file)
@@ -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;
index 46288c0e134bd9cc140c86bed3fe2900591be767..6184dc43153d3f3f12fd6966b057b3bfeb43f649 100644 (file)
@@ -6,6 +6,7 @@ lib/parse-duration.h
 lib/parse-duration.c
 
 Depends-on:
+intprops
 
 configure.ac: