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

Commit 815810e

Browse files
committed
Attempt to fix breakage caused by signed integer conversion patch.
Use INT_MIN rather than INT32_MIN as we do elsewhere in the code, and try to work around nonexistence of INT64_MIN if necessary. Adjust the new regression tests to something hopefully saner, per observation by Tom Lane.
1 parent b58c250 commit 815810e

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

src/backend/utils/adt/numutils.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
#include <limits.h>
1919
#include <ctype.h>
2020

21+
/*
22+
* Defining INT64_MIN as -9223372036854775808LL may not work; the compiler's
23+
* tokenizer may see - as a separate token and then be unable to view
24+
* 9223372036854775808 as a number. This is the standard workaround for that
25+
* problem.
26+
*/
27+
#ifndef INT64_MIN
28+
#define INT64_MIN (-9223372036854775807LL - 1)
29+
#endif
30+
2131
#include "utils/builtins.h"
2232

2333
/*
@@ -136,7 +146,7 @@ pg_ltoa(int32 value, char *a)
136146
* Avoid problems with the most negative integer not being representable
137147
* as a positive integer.
138148
*/
139-
if (value == INT32_MIN)
149+
if (value == INT_MIN)
140150
{
141151
memcpy(a, "-2147483648", 12);
142152
return;

src/test/regress/expected/int2.out

+6-6
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,15 @@ SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
243243
(5 rows)
244244

245245
-- corner cases
246-
SELECT (1<<15-1)::int2::text;
247-
text
248-
-------
249-
16384
246+
SELECT (-1::int2<<15)::text;
247+
text
248+
--------
249+
-32768
250250
(1 row)
251251

252-
SELECT (-1<<15)::int2::text;
252+
SELECT ((-1::int2<<15)+1)::text;
253253
text
254254
--------
255-
-32768
255+
-32767
256256
(1 row)
257257

src/test/regress/expected/int4.out

+7-7
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,16 @@ SELECT (2 + 2) / 2 AS two;
329329
2
330330
(1 row)
331331

332-
-- corner cases
333-
SELECT (1<<31-1)::int4::text;
334-
text
335-
------------
336-
1073741824
332+
-- corner case
333+
SELECT (-1::int4<<31)::text;
334+
text
335+
-------------
336+
-2147483648
337337
(1 row)
338338

339-
SELECT (1<<31)::int4::text;
339+
SELECT ((-1::int4<<31)+1)::text;
340340
text
341341
-------------
342-
-2147483648
342+
-2147483647
343343
(1 row)
344344

src/test/regress/expected/int8.out

+9-9
Original file line numberDiff line numberDiff line change
@@ -802,16 +802,16 @@ SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::in
802802
4567890123456799
803803
(6 rows)
804804

805-
-- corner cases
806-
SELECT (1<<63-1)::int8::text;
807-
text
808-
------------
809-
1073741824
805+
-- corner case
806+
SELECT (-1::int8<<63)::text;
807+
text
808+
----------------------
809+
-9223372036854775808
810810
(1 row)
811811

812-
SELECT (1<<63)::int8::text;
813-
text
814-
-------------
815-
-2147483648
812+
SELECT ((-1::int8<<63)+1)::text;
813+
text
814+
----------------------
815+
-9223372036854775807
816816
(1 row)
817817

src/test/regress/sql/int2.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
8585
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
8686

8787
-- corner cases
88-
SELECT (1<<15-1)::int2::text;
89-
SELECT (-1<<15)::int2::text;
88+
SELECT (-1::int2<<15)::text;
89+
SELECT ((-1::int2<<15)+1)::text;

src/test/regress/sql/int4.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ SELECT 2 + 2 / 2 AS three;
124124

125125
SELECT (2 + 2) / 2 AS two;
126126

127-
-- corner cases
128-
SELECT (1<<31-1)::int4::text;
129-
SELECT (1<<31)::int4::text;
127+
-- corner case
128+
SELECT (-1::int4<<31)::text;
129+
SELECT ((-1::int4<<31)+1)::text;

src/test/regress/sql/int8.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::in
191191
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
192192
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
193193

194-
-- corner cases
195-
SELECT (1<<63-1)::int8::text;
196-
SELECT (1<<63)::int8::text;
194+
-- corner case
195+
SELECT (-1::int8<<63)::text;
196+
SELECT ((-1::int8<<63)+1)::text;

0 commit comments

Comments
 (0)