git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64e401b)
ecpg: Fix return code for overflow in numeric conversion
2024年3月25日 13:18:36 +0000 (14:18 +0100)
2024年3月25日 13:18:36 +0000 (14:18 +0100)
The decimal conversion functions dectoint and dectolong are documented
to return ECPG_INFORMIX_NUM_OVERFLOW in case of overflows, but always
returned -1 on all errors due to incorrectly checking the returnvalue
from the PGTYPES* functions.

Author: Aidar Imamov <a.imamov@postgrespro.ru>
Discussion: https://postgr.es/m/54d2b53327516d9454daa5fb2f893bdc@postgrespro.ru


diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 80d40aa3e09b2c8526f6fdf3148791589ae363b6..8ea89e640a0838945560b76a20af885900eae70a 100644 (file)
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -435,6 +435,7 @@ dectoint(decimal *np, int *ip)
{
int ret;
numeric *nres = PGTYPESnumeric_new();
+ int errnum;
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
@@ -445,10 +446,12 @@ dectoint(decimal *np, int *ip)
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
+ errno = 0;
ret = PGTYPESnumeric_to_int(nres, ip);
+ errnum = errno;
PGTYPESnumeric_free(nres);
- if (ret == PGTYPES_NUM_OVERFLOW)
+ if (ret == -1 && errnum == PGTYPES_NUM_OVERFLOW)
ret = ECPG_INFORMIX_NUM_OVERFLOW;
return ret;
@@ -459,6 +462,7 @@ dectolong(decimal *np, long *lngp)
{
int ret;
numeric *nres = PGTYPESnumeric_new();
+ int errnum;
if (nres == NULL)
return ECPG_INFORMIX_OUT_OF_MEMORY;
@@ -469,10 +473,12 @@ dectolong(decimal *np, long *lngp)
return ECPG_INFORMIX_OUT_OF_MEMORY;
}
+ errno = 0;
ret = PGTYPESnumeric_to_long(nres, lngp);
+ errnum = errno;
PGTYPESnumeric_free(nres);
- if (ret == PGTYPES_NUM_OVERFLOW)
+ if (ret == -1 && errnum == PGTYPES_NUM_OVERFLOW)
ret = ECPG_INFORMIX_NUM_OVERFLOW;
return ret;
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout
index 1f8675b3f3c3be920a0abd9c46332c4f9e7ef95f..71a5afa4a7ad5a562b7d86cb958bff51dde28644 100644 (file)
--- a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout
+++ b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout
@@ -3,8 +3,8 @@
(no errno set) - dec[0,3]: r: -1, *
(no errno set) - dec[0,4]: r: -1, *
dec[0,5]: r: 0, 0.00
-(errno == PGTYPES_NUM_OVERFLOW) - dec[0,6]: 0 (r: -1)
-(errno == PGTYPES_NUM_OVERFLOW) - dec[0,8]: 0 (r: -1)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[0,6]: 0 (r: -1200)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[0,8]: 0 (r: -1200)
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,10]: 0 (r: -1)
dec[1,1]: r: 0, -2
@@ -45,8 +45,8 @@ dec[4,2]: r: 0, 592490000000000000000000
dec[4,3]: r: 0, 592490000000000000000000.0
dec[4,4]: r: 0, 592490000000000000000000.00
dec[4,5]: r: 0, 0.00
-(errno == PGTYPES_NUM_OVERFLOW) - dec[4,6]: 0 (r: -1)
-(errno == PGTYPES_NUM_OVERFLOW) - dec[4,8]: 0 (r: -1)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[4,6]: 0 (r: -1200)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[4,8]: 0 (r: -1200)
dec[4,10]: 5.9249e+23 (r: 0)
dec[5,1]: r: 0, -328400
@@ -141,8 +141,8 @@ dec[13,2]: r: 0, 1234567890123456789012345679
dec[13,3]: r: 0, 1234567890123456789012345678.9
dec[13,4]: r: 0, 1234567890123456789012345678.91
dec[13,5]: r: 0, 0.00
-(errno == PGTYPES_NUM_OVERFLOW) - dec[13,6]: 0 (r: -1)
-(errno == PGTYPES_NUM_OVERFLOW) - dec[13,8]: 0 (r: -1)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[13,6]: 0 (r: -1200)
+(errno == PGTYPES_NUM_OVERFLOW) - dec[13,8]: 0 (r: -1200)
dec[13,10]: 1.23457e+27 (r: 0)
(errno == PGTYPES_NUM_OVERFLOW) - dec[14,0]: r: -1200
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /