diff options
author | Tom Lane | 2009-08-18 21:23:14 +0000 |
---|---|---|
committer | Tom Lane | 2009-08-18 21:23:14 +0000 |
commit | fa8caa0c24826c5db453003833c26f3d593a80ea (patch) | |
tree | b4cb062c708e76a6177ec0a830cda19808f20872 | |
parent | c4b555aaa404d7fec5c8811c48662ba4dcd0318c (diff) |
Fix overflow for INTERVAL 'x ms' where x is more than a couple million,
and integer datetimes are in use. Per bug report from Hubert Depesz
Lubaczewski.
Alex Hunsaker
-rw-r--r-- | src/backend/utils/adt/datetime.c | 3 | ||||
-rw-r--r-- | src/include/utils/timestamp.h | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 78b1c2612b..8c62b83c4d 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -2986,6 +2986,9 @@ DecodeInterval(char **field, int *ftype, int nf, int range, break; case DTK_MILLISEC: + /* avoid overflowing the fsec field */ + tm->tm_sec += val / 1000; + val -= (val / 1000) * 1000; #ifdef HAVE_INT64_TIMESTAMP *fsec += rint((val + fval) * 1000); #else diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index a40c4b6462..45dd2c6f59 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -39,6 +39,8 @@ * TimeOffset and fsec_t are convenience typedefs for temporary variables * that are of different types in the two cases. Do not use fsec_t in values * stored on-disk, since it is not the same size in both implementations. + * Also, fsec_t is only meant for *fractional* seconds; beware of overflow + * if the value you need to store could be many seconds. */ #ifdef HAVE_INT64_TIMESTAMP |