8000 Return error if allocation of new element was not possible. · micdev42/postgres@1b7f516 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b7f516

Browse files
author
Michael Meskes
committed
Return error if allocation of new element was not possible.
Found by Coverity.
1 parent 0caf562 commit 1b7f516

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/interfaces/ecpg/pgtypeslib/numeric.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,18 @@ PGTYPESnumeric_to_asc(numeric *num, int dscale)
402402
numeric *numcopy = PGTYPESnumeric_new();
403403
char *s;
404404

405-
if (dscale < 0)
406-
dscale = num->dscale;
405+
if (numcopy == NULL)
406+
return NULL;
407407

408408
if (PGTYPESnumeric_copy(num, numcopy) < 0)
409409
{
410410
PGTYPESnumeric_free(numcopy);
411411
return NULL;
412412
}
413+
414+
if (dscale < 0)
415+
dscale = num->dscale;
416+
413417
/* get_str_from_var may change its argument */
414418
s = get_str_from_var(numcopy, dscale);
415419
PGTYPESnumeric_free(numcopy);
@@ -1493,6 +1497,9 @@ numericvar_to_double(numeric *var, double *dp)
14931497
char *endptr;
14941498
numeric *varcopy = PGTYPESnumeric_new();
14951499

1500+
if (varcopy == NULL)
1501+
return -1;
1502+
14961503
if (PGTYPESnumeric_copy(var, varcopy) < 0)
14971504
{
14981505
PGTYPESnumeric_free(varcopy);

0 commit comments

Comments
 (0)
0