diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-18 21:23:14 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-18 21:23:14 +0000 |
commit | 3bd2241135d18767cf40fc9a39a4afd4ce3ff3a6 (patch) | |
tree | 9aaddf6680f557ac82d461b6d8175d326057dc11 | |
parent | e31b35faa5f1971ad847f238b6893fb805b74065 (diff) | |
download | postgresql-3bd2241135d18767cf40fc9a39a4afd4ce3ff3a6.tar.gz postgresql-3bd2241135d18767cf40fc9a39a4afd4ce3ff3a6.zip |
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 | 5 | ||||
-rw-r--r-- | src/include/utils/timestamp.h | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 186522148d5..6f0f5ce9863 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.208 2009/06/11 14:49:03 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.209 2009/08/18 21:23:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 291de5cdeac..ad93f9d67ec 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.80 2009/06/11 14:49:13 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.81 2009/08/18 21:23:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 |