From cfd992ecbad2c24eb10746e5128c3cd769454441 Mon Sep 17 00:00:00 2001 From: Michael Meskes <meskes@postgresql.org> Date: Tue, 7 Oct 2003 18:36:46 +0000 Subject: [PATCH] Fixed floating point exception in long=>numeric conversion. --- src/interfaces/ecpg/ChangeLog | 4 ++++ src/interfaces/ecpg/pgtypeslib/numeric.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index ce7fe1e7111..1bea5b8e22b 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1679,6 +1679,10 @@ Mon Oct 6 08:41:45 CEST 2003 Tue Oct 7 07:45:09 CEST 2003 - Fixed error handling in rstrdate. + +Tue Oct 7 20:26:06 CEST 2003 + + - Fixed floating point exception in long=>numeric transformation. - Set ecpg version to 3.0.0 - Set ecpg library to 4.0.0 - Set pgtypes library to 1.0.0 diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c index 569bcb23b4f..872d2e69e77 100644 --- a/src/interfaces/ecpg/pgtypeslib/numeric.c +++ b/src/interfaces/ecpg/pgtypeslib/numeric.c @@ -1338,6 +1338,7 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var) signed long int extract; signed long int reach_limit; + printf("l=%ld\n", long_val); if (abs_long_val < 0) { abs_long_val *= -1; @@ -1351,10 +1352,19 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var) { size++; reach_limit *= 10; - } while ((reach_limit - 1) < abs_long_val); + } while ((reach_limit - 1) < abs_long_val && reach_limit <= LONG_MAX/10); - /* always add a .0 */ - size++; + if (reach_limit <= LONG_MAX/10) + { + /* add the first digit and a .0 */ + size += 2; + } + else + { + /* always add a .0 */ + size++; + reach_limit /= 10; + } if (alloc_var(var, size) < 0) return -1; @@ -1366,11 +1376,11 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var) i = 0; do { - reach_limit /= 10; extract = abs_long_val - (abs_long_val % reach_limit); var->digits[i] = extract / reach_limit; abs_long_val -= extract; i++; + reach_limit /= 10; /* * we can abandon if abs_long_val reaches 0, because the memory is -- GitLab