Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Return error if allocation of new element was not possible.
authorMichael Meskes <meskes@postgresql.org>
Sun, 8 Sep 2013 10:59:43 +0000 (12:59 +0200)
committerMichael Meskes <meskes@postgresql.org>
Sun, 8 Sep 2013 11:15:04 +0000 (13:15 +0200)
Found by Coverity.

src/interfaces/ecpg/pgtypeslib/numeric.c

index 93505eaab187cf05b232257357b34b72bf54b758..7ec252c445684f8bf9a3acc129f98c234cec3d4f 100644 (file)
@@ -402,14 +402,18 @@ PGTYPESnumeric_to_asc(numeric *num, int dscale)
    numeric    *numcopy = PGTYPESnumeric_new();
    char       *s;
 
-   if (dscale < 0)
-       dscale = num->dscale;
+   if (numcopy == NULL)
+       return NULL;
 
    if (PGTYPESnumeric_copy(num, numcopy) < 0)
    {
        PGTYPESnumeric_free(numcopy);
        return NULL;
    }
+
+   if (dscale < 0)
+       dscale = num->dscale;
+
    /* get_str_from_var may change its argument */
    s = get_str_from_var(numcopy, dscale);
    PGTYPESnumeric_free(numcopy);
@@ -1493,6 +1497,9 @@ numericvar_to_double(numeric *var, double *dp)
    char       *endptr;
    numeric    *varcopy = PGTYPESnumeric_new();
 
+   if (varcopy == NULL)
+       return -1;
+
    if (PGTYPESnumeric_copy(var, varcopy) < 0)
    {
        PGTYPESnumeric_free(varcopy);