Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77be5f9

Browse files
committed
AdjustTimestampForTypmod does not work (at least not portably) on
-infinity and +infinity. Put TIMESTAMP_NOT_FINITE guard into the routine, instead of forgetting it at some call sites. Fixes regression test failures here.
1 parent a390975 commit 77be5f9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.52 2001/10/03 05:29:24 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.53 2001/10/03 15:50:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,8 +32,7 @@
3232
static double time2t(const int hour, const int min, const double sec);
3333
static int EncodeSpecialTimestamp(Timestamp dt, char *str);
3434
static Timestamp dt2local(Timestamp dt, int timezone);
35-
static void
36-
AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
35+
static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
3736

3837

3938
/*****************************************************************************
@@ -138,16 +137,16 @@ timestamp_scale(PG_FUNCTION_ARGS)
138137

139138
result = timestamp;
140139

141-
if (! TIMESTAMP_NOT_FINITE(result))
142-
AdjustTimestampForTypmod(&result, typmod);
140+
AdjustTimestampForTypmod(&result, typmod);
143141

144142
PG_RETURN_TIMESTAMP(result);
145143
}
146144

147145
static void
148146
AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
149147
{
150-
if ((typmod >= 0) && (typmod <= 13))
148+
if (! TIMESTAMP_NOT_FINITE(*time) &&
149+
(typmod >= 0) && (typmod <= 13))
151150
{
152151
static double TimestampScale = 1;
153152
static int32 TimestampTypmod = 0;
@@ -157,8 +156,6 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
157156

158157
*time = (rint(((double) *time)*TimestampScale)/TimestampScale);
159158
}
160-
161-
return;
162159
}
163160

164161

@@ -261,8 +258,7 @@ timestamptz_scale(PG_FUNCTION_ARGS)
261258

262259
result = timestamp;
263260

264-
if (! TIMESTAMP_NOT_FINITE(result))
265-
AdjustTimestampForTypmod(&result, typmod);
261+
AdjustTimestampForTypmod(&result, typmod);
266262

267263
PG_RETURN_TIMESTAMPTZ(result);
268264
}

0 commit comments

Comments
 (0)