File tree 1 file changed +12
-3
lines changed 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 14
14
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
15
15
*
16
16
* 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 $
18
18
*
19
19
*-------------------------------------------------------------------------
20
20
*/
@@ -2983,6 +2983,7 @@ numericvar_to_int8(NumericVar *var, int64 *result)
2983
2983
{
2984
2984
NumericDigit * digits ;
2985
2985
int ndigits ;
2986
+ int weight ;
2986
2987
int i ;
2987
2988
int64 val ,
2988
2989
oldval ;
@@ -3000,15 +3001,23 @@ numericvar_to_int8(NumericVar *var, int64 *result)
3000
3001
return true;
3001
3002
}
3002
3003
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
+
3003
3011
/* Construct the result */
3004
3012
digits = var -> digits ;
3005
3013
neg = (var -> sign == NUMERIC_NEG );
3006
3014
val = digits [0 ];
3007
- for (i = 1 ; i < ndigits ; i ++ )
3015
+ for (i = 1 ; i <= weight ; i ++ )
3008
3016
{
3009
3017
oldval = val ;
3010
3018
val *= NBASE ;
3011
- val += digits [i ];
3019
+ if (i < ndigits )
3020
+ val += digits [i ];
3012
3021
/*
3013
3022
* The overflow check is a bit tricky because we want to accept
3014
3023
* INT64_MIN, which will overflow the positive accumulator. We
You can’t perform that action at this time.
0 commit comments