From e33c6b10c415d967617b48aefe4fe420616f0ed4 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 22 Jul 2005 21:52:31 +0000 Subject: [PATCH] =?utf8?q?Fix=20some=20errors=20found=20by=20static=20sour?= =?utf8?q?ce=20analysis=20(using=20Klocwork).=20[Tomas=20Sk=C3=A4re]?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- connection.c | 9 +++++++++ convert.c | 2 +- info.c | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/connection.c b/connection.c index cc9f911..220409f 100644 --- a/connection.c +++ b/connection.c @@ -2360,13 +2360,20 @@ CC_Constructor() CC_conninfo_init(&(rv->connInfo)); rv->stmts = (StatementClass **) malloc(sizeof(StatementClass *) * STMT_INCREMENT); if (!rv->stmts) + { + free(rv); return NULL; + } memset(rv->stmts, 0, sizeof(StatementClass *) * STMT_INCREMENT); rv->num_stmts = STMT_INCREMENT; rv->descs = (DescriptorClass **) malloc(sizeof(DescriptorClass *) * STMT_INCREMENT); if (!rv->descs) + { + free(rv->stmts); + free(rv); return NULL; + } memset(rv->descs, 0, sizeof(DescriptorClass *) * STMT_INCREMENT); rv->num_descs = STMT_INCREMENT; @@ -2857,6 +2864,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, UDWORD flag) if((!res) || (res->status == PGRES_EMPTY_QUERY) ) { QR_Destructor(res); + res = NULL; goto cleanup; } else @@ -3141,6 +3149,7 @@ LIBPQ_execute_query(ConnectionClass *self,char *query) { CC_set_error(self, CONNECTION_COULD_NOT_RECEIVE, "Could not allocate memory for result set"); QR_Destructor(qres); + return NULL; } qres->status = PQresultStatus(pgres); if( (PQresultStatus(pgres) == PGRES_COMMAND_OK) ) diff --git a/convert.c b/convert.c index c492161..23a7943 100644 --- a/convert.c +++ b/convert.c @@ -1578,7 +1578,7 @@ do { \ while (qp->statement[qp->opos] != '\0' && qp->statement[qp->opos] != ch) \ { \ buf[c++] = qp->statement[qp->opos++]; \ - if (c >= maxsize) \ + if (c >= maxsize - 1) \ break; \ } \ if (qp->statement[qp->opos] == '\0') \ diff --git a/info.c b/info.c index ff26d09..4d8de95 100644 --- a/info.c +++ b/info.c @@ -1304,7 +1304,7 @@ retry_public_schema: #else prefix[i] = strtok(prefixes, ";"); #endif /* HAVE_STRTOK_R */ - while (prefix[i] && i < sizeof(prefix)) + while (i < 31 && prefix[i]) #ifdef HAVE_STRTOK_R prefix[++i] = strtok_r(NULL, ";", &last); #else @@ -1328,7 +1328,7 @@ retry_public_schema: #else table_type[i] = strtok(table_types, ","); #endif /* HAVE_STRTOK_R */ - while (table_type[i] && i < 32) + while (i < 31 && table_type[i]) #ifdef HAVE_STRTOK_R table_type[++i] = strtok_r(NULL, ",", &last); #else -- 2.39.5