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

Appearance settings

Commit bc43b7c

Browse filesBrowse files
committed
Fix numeric_power() when the exponent is INT_MIN.
In power_var_int(), the computation of the number of significant digits to use in the computation used log(Abs(exp)), which isn't safe because Abs(exp) returns INT_MIN when exp is INT_MIN. Use fabs() instead of Abs(), so that the exponent is cast to a double before the absolute value is taken. Back-patch to 9.6, where this was introduced (by 7d9a473). Discussion: https://postgr.es/m/CAEZATCVd6pMkz=BrZEgBKyqqJrt2xghr=fNc8+Z=5xC6cgWrWA@mail.gmail.com
1 parent 5a3574d commit bc43b7c
Copy full SHA for bc43b7c

File tree

Expand file treeCollapse file tree

3 files changed

+8
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/numeric.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10290,7 +10290,7 @@ power_var_int(const NumericVar *base, int exp, NumericVar *result, int rscale)
1029010290
* to around log10(abs(exp)) digits, so work with this many extra digits
1029110291
* of precision (plus a few more for good measure).
1029210292
*/
10293-
sig_digits += (int) log(Abs(exp)) + 8;
10293+
sig_digits += (int) log(fabs(exp)) + 8;
1029410294

1029510295
/*
1029610296
* Now we can proceed with the multiplications.

‎src/test/regress/expected/numeric.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/numeric.out
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,12 @@ select 0.12 ^ (-20);
23212321
2608405330458882702.5529619561355838
23222322
(1 row)
23232323

2324+
select 1.000000000123 ^ (-2147483648);
2325+
?column?
2326+
--------------------
2327+
0.7678656556403084
2328+
(1 row)
2329+
23242330
-- cases that used to error out
23252331
select 0.12 ^ (-25);
23262332
?column?

‎src/test/regress/sql/numeric.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/numeric.sql
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ select 3.789 ^ 21;
10891089
select 3.789 ^ 35;
10901090
select 1.2 ^ 345;
10911091
select 0.12 ^ (-20);
1092+
select 1.000000000123 ^ (-2147483648);
10921093

10931094
-- cases that used to error out
10941095
select 0.12 ^ (-25);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.