Fixed remaining Coverity bugs.
authorMichael Meskes
Wed, 5 Jul 2006 10:49:56 +0000 (10:49 +0000)
committerMichael Meskes
Wed, 5 Jul 2006 10:49:56 +0000 (10:49 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ecpglib/descriptor.c
src/interfaces/ecpg/ecpglib/execute.c

index 8196449cf455b9fc6792aebf96784c9bf8929051..a89722bb647444cb7b92c7695456466698931e5c 100644 (file)
@@ -2040,5 +2040,9 @@ Mo Jun 26 16:08:23 CEST 2006
 
    - Added missing braces to prevent a segfault after usage of an
      undeclared cursor.
+
+We Jul  5 12:17:28 CEST 2006
+
+   - Fixed remaining Coverity bugs.
    - Set ecpg library version to 5.2.
    - Set ecpg version to 4.2.1.
index 9a3086bdda7ed7e20fb7ce00ae508f77ac21cdb5..c0ee7684c3940212b6f0f6849e064e47dda98a5e 100644 (file)
@@ -1,6 +1,6 @@
 /* dynamic SQL support routines
  *
- * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.16 2006/06/25 09:38:39 meskes Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.17 2006/07/05 10:49:56 meskes Exp $
  */
 
 #define POSTGRES_ECPG_INTERNAL
@@ -249,7 +249,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
                data_var.ind_varcharsize = varcharsize;
                data_var.ind_arrsize = arrsize;
                data_var.ind_offset = offset;
-               if (data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0)
+               if ((data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0) && data_var.ind_pointer != NULL)
                    data_var.ind_value = *((void **) (data_var.ind_pointer));
                else
                    data_var.ind_value = data_var.ind_pointer;
@@ -397,7 +397,8 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
        setlocale(LC_NUMERIC, oldlocale);
        ECPGfree(oldlocale);
    }
-   else if (data_var.ind_type != ECPGt_NO_INDICATOR)
+   else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
+   /* ind_type != NO_INDICATOR should always have ind_pointer != NULL but since this might be changed manually in the .c file let's play it safe */
    {
        /*
         * this is like ECPGstore_result but since we don't have a data
@@ -410,8 +411,9 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
            ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
            return false;
        }
+
        /* allocate storage if needed */
-       if (data_var.ind_arrsize == 0 && data_var.ind_pointer != NULL && data_var.ind_value == NULL)
+       if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
        {
            void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
            if (!mem)
@@ -420,6 +422,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
            ECPGadd_mem(mem, lineno);
            data_var.ind_value = mem;
        }
+
        for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
        {
            if (!get_int_item(lineno, data_var.ind_value, data_var.ind_type, -PQgetisnull(ECPGresult, act_tuple, index)))
index 0ac6b909807094e5bfcdb43ca72bb9233310f9ea..348b652f8ac39ebb137f7ce8dd8094527f66d8ba 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.50 2006/06/26 09:20:09 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.51 2006/07/05 10:49:56 meskes Exp $ */
 
 /*
  * The aim is to get a simpler inteface to the database routines.
@@ -876,12 +876,13 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
                {
                    char       *str = NULL;
                    int     slen;
-                   numeric    *nval = PGTYPESnumeric_new();
+                   numeric    *nval;
 
                    if (var->arrsize > 1)
                    {
-                       for (element = 0; element < var->arrsize; element++, nval = PGTYPESnumeric_new())
+                       for (element = 0; element < var->arrsize; element++)
                        {
+                           nval = PGTYPESnumeric_new();
                            if (!nval)
                                return false;
                                
@@ -911,6 +912,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
                    }
                    else
                    {
+                       nval = PGTYPESnumeric_new();
                        if (!nval)
                            return false;
 
@@ -1048,16 +1050,22 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 
            case ECPGt_timestamp:
                {
-                   char       *str = NULL;
+                   char       *str = NULL, *asc = NULL;
                    int         slen;
 
                    if (var->arrsize > 1)
                    {
                        for (element = 0; element < var->arrsize; element++)
                        {
-                           str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), lineno);
+                           asc = PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value));
+                           if (!asc)
+                               return false;
+
+                           str = quote_postgres(asc, lineno);
+                           ECPGfree(asc); /* we don't need this anymore so free it asap. */
                            if (!str)
                                return false;
+
                            slen = strlen(str);
 
                            if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))
@@ -1077,7 +1085,12 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
                    }
                    else
                    {
-                       str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), lineno);
+                       asc = PGTYPEStimestamp_to_asc(*(timestamp *) (var->value));
+                       if (!asc)
+                           return false;
+
+                       str = quote_postgres(asc, lineno);
+                       ECPGfree(asc); /* we don't need this anymore so free it asap. */
                        if (!str)
                            return false;
                        slen = strlen(str);