Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit815810e

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, andtry to work around nonexistence of INT64_MIN if necessary. Adjust thenew regression tests to something hopefully saner, per observation byTom Lane.
1 parentb58c250 commit815810e

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

‎src/backend/utils/adt/numutils.c

Lines changed: 11 additions & 1 deletion
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+
#ifndefINT64_MIN
28+
#defineINT64_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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 7 additions & 7 deletions
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-
-- cornercases
333-
SELECT (1<<31-1)::int4::text;
334-
text
335-
------------
336-
1073741824
332+
-- cornercase
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

Lines changed: 9 additions & 9 deletions
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-
-- cornercases
806-
SELECT (1<<63-1)::int8::text;
807-
text
808-
------------
809-
1073741824
805+
-- cornercase
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

Lines changed: 2 additions & 2 deletions
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 xFROM 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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ SELECT 2 + 2 / 2 AS three;
124124

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

127-
-- cornercases
128-
SELECT (1<<31-1)::int4::text;
129-
SELECT (1<<31)::int4::text;
127+
-- cornercase
128+
SELECT (-1::int4<<31)::text;
129+
SELECT ((-1::int4<<31)+1)::text;

‎src/test/regress/sql/int8.sql

Lines changed: 3 additions & 3 deletions
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-
-- cornercases
195-
SELECT (1<<63-1)::int8::text;
196-
SELECT (1<<63)::int8::text;
194+
-- cornercase
195+
SELECT (-1::int8<<63)::text;
196+
SELECT ((-1::int8<<63)+1)::text;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp