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

Appearance settings

Commit b2d6b4c

Browse filesBrowse files
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
1 parent 64e401b commit b2d6b4c
Copy full SHA for b2d6b4c

File tree

Expand file treeCollapse file tree

2 files changed

+14
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-8
lines changed

‎src/interfaces/ecpg/compatlib/informix.c

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/compatlib/informix.c
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ dectoint(decimal *np, int *ip)
435435
{
436436
int ret;
437437
numeric *nres = PGTYPESnumeric_new();
438+
int errnum;
438439

439440
if (nres == NULL)
440441
return ECPG_INFORMIX_OUT_OF_MEMORY;
@@ -445,10 +446,12 @@ dectoint(decimal *np, int *ip)
445446
return ECPG_INFORMIX_OUT_OF_MEMORY;
446447
}
447448

449+
errno = 0;
448450
ret = PGTYPESnumeric_to_int(nres, ip);
451+
errnum = errno;
449452
PGTYPESnumeric_free(nres);
450453

451-
if (ret == PGTYPES_NUM_OVERFLOW)
454+
if (ret == -1 && errnum == PGTYPES_NUM_OVERFLOW)
452455
ret = ECPG_INFORMIX_NUM_OVERFLOW;
453456

454457
return ret;
@@ -459,6 +462,7 @@ dectolong(decimal *np, long *lngp)
459462
{
460463
int ret;
461464
numeric *nres = PGTYPESnumeric_new();
465+
int errnum;
462466

463467
if (nres == NULL)
464468
return ECPG_INFORMIX_OUT_OF_MEMORY;
@@ -469,10 +473,12 @@ dectolong(decimal *np, long *lngp)
469473
return ECPG_INFORMIX_OUT_OF_MEMORY;
470474
}
471475

476+
errno = 0;
472477
ret = PGTYPESnumeric_to_long(nres, lngp);
478+
errnum = errno;
473479
PGTYPESnumeric_free(nres);
474480

475-
if (ret == PGTYPES_NUM_OVERFLOW)
481+
if (ret == -1 && errnum == PGTYPES_NUM_OVERFLOW)
476482
ret = ECPG_INFORMIX_NUM_OVERFLOW;
477483

478484
return ret;

‎src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/test/expected/compat_informix-dec_test.stdout
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
(no errno set) - dec[0,3]: r: -1, *
44
(no errno set) - dec[0,4]: r: -1, *
55
dec[0,5]: r: 0, 0.00
6-
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,6]: 0 (r: -1)
7-
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,8]: 0 (r: -1)
6+
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,6]: 0 (r: -1200)
7+
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,8]: 0 (r: -1200)
88
(errno == PGTYPES_NUM_OVERFLOW) - dec[0,10]: 0 (r: -1)
99

1010
dec[1,1]: r: 0, -2
@@ -45,8 +45,8 @@ dec[4,2]: r: 0, 592490000000000000000000
4545
dec[4,3]: r: 0, 592490000000000000000000.0
4646
dec[4,4]: r: 0, 592490000000000000000000.00
4747
dec[4,5]: r: 0, 0.00
48-
(errno == PGTYPES_NUM_OVERFLOW) - dec[4,6]: 0 (r: -1)
49-
(errno == PGTYPES_NUM_OVERFLOW) - dec[4,8]: 0 (r: -1)
48+
(errno == PGTYPES_NUM_OVERFLOW) - dec[4,6]: 0 (r: -1200)
49+
(errno == PGTYPES_NUM_OVERFLOW) - dec[4,8]: 0 (r: -1200)
5050
dec[4,10]: 5.9249e+23 (r: 0)
5151

5252
dec[5,1]: r: 0, -328400
@@ -141,8 +141,8 @@ dec[13,2]: r: 0, 1234567890123456789012345679
141141
dec[13,3]: r: 0, 1234567890123456789012345678.9
142142
dec[13,4]: r: 0, 1234567890123456789012345678.91
143143
dec[13,5]: r: 0, 0.00
144-
(errno == PGTYPES_NUM_OVERFLOW) - dec[13,6]: 0 (r: -1)
145-
(errno == PGTYPES_NUM_OVERFLOW) - dec[13,8]: 0 (r: -1)
144+
(errno == PGTYPES_NUM_OVERFLOW) - dec[13,6]: 0 (r: -1200)
145+
(errno == PGTYPES_NUM_OVERFLOW) - dec[13,8]: 0 (r: -1200)
146146
dec[13,10]: 1.23457e+27 (r: 0)
147147

148148
(errno == PGTYPES_NUM_OVERFLOW) - dec[14,0]: r: -1200

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.