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

Commit 0fc7779

Browse files
committed
Revise overflow test in int84() to avoid codegen bug in some older
versions of gcc. We don't really need to explicitly test the limits anyway, just reverse-convert and see if we get the same answer.
1 parent de77c55 commit 0fc7779

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/backend/utils/adt/int8.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.32 2001/08/24 14:07:49 petere Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.33 2001/09/07 01:33:44 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -67,7 +67,7 @@ int8in(PG_FUNCTION_ARGS)
6767
* Do our own scan, rather than relying on sscanf which might be
6868
* broken for long long.
6969
*/
70-
while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */
70+
while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */
7171
ptr++;
7272
if (*ptr == '-') /* handle sign */
7373
sign = -1, ptr++;
@@ -688,11 +688,12 @@ int84(PG_FUNCTION_ARGS)
688688
int64 val = PG_GETARG_INT64(0);
689689
int32 result;
690690

691-
if ((val < INT_MIN) || (val > INT_MAX))
692-
elog(ERROR, "int8 conversion to int4 is out of range");
693-
694691
result = (int32) val;
695692

693+
/* Test for overflow by reverse-conversion. */
694+
if ((int64) result != val)
695+
elog(ERROR, "int8 conversion to int4 is out of range");
696+
696697
PG_RETURN_INT32(result);
697698
}
698699

0 commit comments

Comments
 (0)