mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
ecpg: Fix return code for overflow in numeric conversion
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user