Skip to content

Commit 9fc6f4e

Browse files
committed
Win32 can't catch the exception thrown by INT_MIN / -1 or INT_MIN * -1,
so on that platform we test for those before the computation and throw an "out of range" error. Backpatch to 8.1.X.
1 parent e71e02d commit 9fc6f4e

File tree

1 file changed

+23
-1
lines changed
  • src/backend/utils/adt

1 file changed

+23
-1
lines changed

src/backend/utils/adt/int.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.72 2006/03/11 01:19:22 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.73 2006/06/12 16:09:11 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -735,6 +735,17 @@ int4mul(PG_FUNCTION_ARGS)
735735
int32 arg2 = PG_GETARG_INT32(1);
736736
int32 result;
737737

738+
#ifdef WIN32
739+
/*
740+
* Win32 doesn't throw a catchable exception for
741+
* SELECT -2147483648 /* INT_MIN */ * (-1);
742+
*/
743+
if (arg2 == -1 && arg1 == INT_MIN)
744+
ereport(ERROR,
745+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
746+
errmsg("integer out of range")));
747+
#endif
748+
738749
result = arg1 * arg2;
739750

740751
/*
@@ -770,6 +781,17 @@ int4div(PG_FUNCTION_ARGS)
770781
(errcode(ERRCODE_DIVISION_BY_ZERO),
771782
errmsg("division by zero")));
772783

784+
#ifdef WIN32
785+
/*
786+
* Win32 doesn't throw a catchable exception for
787+
* SELECT -2147483648 /* INT_MIN */ / (-1);
788+
*/
789+
if (arg2 == -1 && arg1 == INT_MIN)
790+
ereport(ERROR,
791+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
792+
errmsg("integer out of range")));
793+
#endif
794+
773795
result = arg1 / arg2;
774796

775797
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy