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

Commitcdb8a84

Browse files
committed
Fix bug I introduced in recent rewrite of NUMERIC code: numeric to
integer conversions gave the wrong answer for values with strippedtrailing zeroes, such as 10000000.
1 parentb89140a commitcdb8a84

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.61 2003/05/12 23:08:50 tgl Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.62 2003/07/03 19:41:47 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -2983,6 +2983,7 @@ numericvar_to_int8(NumericVar *var, int64 *result)
29832983
{
29842984
NumericDigit*digits;
29852985
intndigits;
2986+
intweight;
29862987
inti;
29872988
int64val,
29882989
oldval;
@@ -3000,15 +3001,23 @@ numericvar_to_int8(NumericVar *var, int64 *result)
30003001
return true;
30013002
}
30023003

3004+
/*
3005+
* For input like 10000000000, we must treat stripped digits as real.
3006+
* So the loop assumes there are weight+1 digits before the decimal point.
3007+
*/
3008+
weight=var->weight;
3009+
Assert(weight >=0&&ndigits <=weight+1);
3010+
30033011
/* Construct the result */
30043012
digits=var->digits;
30053013
neg= (var->sign==NUMERIC_NEG);
30063014
val=digits[0];
3007-
for (i=1;i<ndigits;i++)
3015+
for (i=1;i <=weight;i++)
30083016
{
30093017
oldval=val;
30103018
val *=NBASE;
3011-
val+=digits[i];
3019+
if (i<ndigits)
3020+
val+=digits[i];
30123021
/*
30133022
* The overflow check is a bit tricky because we want to accept
30143023
* INT64_MIN, which will overflow the positive accumulator. We

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp