summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2014-06-17 08:29:46 -0700
committerJim Meyering <meyering@fb.com>2014-06-17 08:31:37 -0700
commit831da41cbc76ecc67cdb0ca24c0f3b0f33181848 (patch)
tree8b87f91fad79ebe1112d521b4a571955b7c383a9 /lib
parentecc31417bea430ede6afd3781cec49c04c184c04 (diff)
downloadgnulib-831da41cbc76ecc67cdb0ca24c0f3b0f33181848.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/parse-duration.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/parse-duration.c b/lib/parse-duration.c
index 037e81e412..82a11938ee 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;