aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-05-01 19:29:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-05-01 19:29:07 +0000
commitfe1b07a6f9f476b08301e9a7fddacaa427f949df (patch)
treeb51de220e124a2ed98e949bf22df0532c31a7ef5
parentcfb61be9cf81765aa23885341f7987ee7f86c9d0 (diff)
downloadpostgresql-fe1b07a6f9f476b08301e9a7fddacaa427f949df.tar.gz
postgresql-fe1b07a6f9f476b08301e9a7fddacaa427f949df.zip
When checking for datetime field overflow, we should allow a fractional-second
part that rounds up to exactly 1.0 second. The previous coding rejected input like "00:12:57.9999999999999999999999999999", with the exact number of nines needed to cause failure varying depending on float-timestamp option and possibly on platform. Obviously this should round up to the next integral second, if we don't have enough precision to distinguish the value from that. Per bug #4789 from Robert Kruus. In passing, fix a missed check for fractional seconds in one copy of the "is it greater than 24:00:00" code. Broken all the way back, so patch all the way back.
-rw-r--r--src/backend/utils/adt/datetime.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 034e030f72e..4e298d77714 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.203 2009/03/22 01:12:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.204 2009/05/01 19:29:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -950,7 +950,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
*/
/* test for > 24:00:00 */
if (tm->tm_hour > 24 ||
- (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0)))
+ (tm->tm_hour == 24 &&
+ (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0)))
return DTERR_FIELD_OVERFLOW;
break;
@@ -2058,15 +2059,13 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
tm->tm_sec < 0 || tm->tm_sec > 60 || tm->tm_hour > 24 ||
- /* test for > 24:00:00 */
+ /* test for > 24:00:00 */
+ (tm->tm_hour == 24 &&
+ (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0)) ||
#ifdef HAVE_INT64_TIMESTAMP
- (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0 ||
- *fsec > INT64CONST(0))) ||
- *fsec < INT64CONST(0) || *fsec >= USECS_PER_SEC
+ *fsec < INT64CONST(0) || *fsec > USECS_PER_SEC
#else
- (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0 ||
- *fsec > 0)) ||
- *fsec < 0 || *fsec >= 1
+ *fsec < 0 || *fsec > 1
#endif
)
return DTERR_FIELD_OVERFLOW;
@@ -2386,11 +2385,11 @@ DecodeTime(char *str, int fmask, int range,
#ifdef HAVE_INT64_TIMESTAMP
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < INT64CONST(0) ||
- *fsec >= USECS_PER_SEC)
+ *fsec > USECS_PER_SEC)
return DTERR_FIELD_OVERFLOW;
#else
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
- tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec >= 1)
+ tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec > 1)
return DTERR_FIELD_OVERFLOW;
#endif