Changeset: e9e22e3bcb5f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e9e22e3bcb5f
Modified Files:
clients/mapilib/mapi.c
clients/odbc/driver/SQLBrowseConnect.c
clients/odbc/driver/SQLGetDescField.c
clients/odbc/driver/SQLGetInfo.c
clients/odbc/driver/SQLGetStmtAttr.c
gdk/gdk_bbp.c
gdk/gdk_storage.c
Branch: Oct2014
Log Message:
Coverity-inspired changes.
All but one were false positives. :-(
diffs (240 lines):
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4289,8 +4289,11 @@ mapi_query_part(MapiHdl hdl, const char
char *q;
if (sz < 512 &&
- (q = realloc(hdl->query, sz + size + 1)) != NULL)
- hdl->query = strncat(q, query, size);
+ (q = realloc(hdl->query, sz + size + 1)) != NULL) {
+ strncpy(q + sz, query, size);
+ q[sz + size] = 0;
+ hdl->query = q;
+ }
}
if (mid->trace == MAPI_TRACE) {
diff --git a/clients/odbc/driver/SQLBrowseConnect.c
b/clients/odbc/driver/SQLBrowseConnect.c
--- a/clients/odbc/driver/SQLBrowseConnect.c
+++ b/clients/odbc/driver/SQLBrowseConnect.c
@@ -66,8 +66,10 @@ MNDBBrowseConnect(ODBCDbc *dbc,
SQLSMALLINT len = 0;
char buf[256];
int n;
+ SQLRETURN rc;
+#ifdef ODBCDEBUG
int allocated = 0;
- SQLRETURN rc;
+#endif
fixODBCstring(InConnectionString, StringLength1, SQLSMALLINT,
addDbcError, dbc, return SQL_ERROR);
@@ -82,32 +84,37 @@ MNDBBrowseConnect(ODBCDbc *dbc,
return SQL_ERROR;
}
- dsn = dbc->dsn;
- uid = dbc->uid;
- pwd = dbc->pwd;
- host = dbc->host;
+ dsn = dbc->dsn ? strdup(dbc->dsn) : NULL;
+ uid = dbc->uid ? strdup(dbc->uid) : NULL;
+ pwd = dbc->pwd ? strdup(dbc->pwd) : NULL;
+ host = dbc->host ? strdup(dbc->host) : NULL;
port = dbc->port;
- dbname = dbc->dbname;
+ dbname = dbc->dbname ? strdup(dbc->dbname) : NULL;
while ((n = ODBCGetKeyAttr(&InConnectionString, &StringLength1, &key,
&attr)) > 0) {
if (strcasecmp(key, "dsn") == 0 && dsn == NULL) {
+ if (dsn)
+ free(dsn);
dsn = attr;
- allocated |= 1;
} else if (strcasecmp(key, "uid") == 0 && uid == NULL) {
+ if (uid)
+ free(uid);
uid = attr;
- allocated |= 2;
} else if (strcasecmp(key, "pwd") == 0 && pwd == NULL) {
+ if (pwd)
+ free(pwd);
pwd = attr;
- allocated |= 4;
} else if (strcasecmp(key, "host") == 0 && host == NULL) {
+ if (host)
+ free(host);
host = attr;
- allocated |= 8;
} else if (strcasecmp(key, "port") == 0 && port == 0) {
port = atoi(attr);
free(attr);
} else if (strcasecmp(key, "database") == 0 && dbname == NULL) {
+ if (dbname)
+ free(dbname);
dbname = attr;
- allocated |= 16;
#ifdef ODBCDEBUG
} else if (strcasecmp(key, "logfile") == 0 &&
getenv("ODBCDEBUG") == NULL) {
@@ -115,7 +122,7 @@ MNDBBrowseConnect(ODBCDbc *dbc,
if (ODBCdebug)
free((void *) ODBCdebug); /* discard const */
ODBCdebug = attr;
- allocated |= 32;
+ allocated = 1;
#endif
} else
free(attr);
@@ -131,7 +138,6 @@ MNDBBrowseConnect(ODBCDbc *dbc,
uid = strdup(buf);
if (uid == NULL)
goto nomem;
- allocated |= 2;
}
}
if (pwd == NULL) {
@@ -140,7 +146,6 @@ MNDBBrowseConnect(ODBCDbc *dbc,
pwd = strdup(buf);
if (pwd == NULL)
goto nomem;
- allocated |= 4;
}
}
if (host == NULL) {
@@ -149,7 +154,6 @@ MNDBBrowseConnect(ODBCDbc *dbc,
host = strdup(buf);
if (host == NULL)
goto nomem;
- allocated |= 8;
}
}
if (port == 0) {
@@ -164,11 +168,10 @@ MNDBBrowseConnect(ODBCDbc *dbc,
dbname = strdup(buf);
if (dbname == NULL)
goto nomem;
- allocated |= 16;
}
}
#ifdef ODBCDEBUG
- if ((allocated & 32) == 0 && getenv("ODBCDEBUG") == NULL) {
+ if (!allocated && getenv("ODBCDEBUG") == NULL) {
/* if not set from InConnectionString argument
* or environment, look in profile */
n = SQLGetPrivateProfileString(dsn, "logfile", "", buf,
sizeof(buf), "odbc.ini");
@@ -240,15 +243,15 @@ MNDBBrowseConnect(ODBCDbc *dbc,
}
bailout:
- if (allocated & 1)
+ if (dsn)
free(dsn);
- if (allocated & 2)
+ if (uid)
free(uid);
- if (allocated & 4)
+ if (pwd)
free(pwd);
- if (allocated & 8)
+ if (host)
free(host);
- if (allocated & 16)
+ if (dbname)
free(dbname);
return rc;
diff --git a/clients/odbc/driver/SQLGetDescField.c
b/clients/odbc/driver/SQLGetDescField.c
--- a/clients/odbc/driver/SQLGetDescField.c
+++ b/clients/odbc/driver/SQLGetDescField.c
@@ -137,8 +137,12 @@ MNDBGetDescField(ODBCDesc *desc,
WriteData(ValuePtr, rec->sql_desc_concise_type, SQLSMALLINT);
return SQL_SUCCESS;
case SQL_DESC_DATA_PTR: /* SQLPOINTER */
+#ifndef STATIC_CODE_ANALYSIS
+ /* Coverity doesn't like the debug print in WriteData,
+ * so we hide this whole thing */
if (!isIRD(desc))
WriteData(ValuePtr, rec->sql_desc_data_ptr, SQLPOINTER);
+#endif
return SQL_SUCCESS;
case SQL_DESC_DATETIME_INTERVAL_CODE: /* SQLSMALLINT */
WriteData(ValuePtr, rec->sql_desc_datetime_interval_code,
SQLSMALLINT);
diff --git a/clients/odbc/driver/SQLGetInfo.c b/clients/odbc/driver/SQLGetInfo.c
--- a/clients/odbc/driver/SQLGetInfo.c
+++ b/clients/odbc/driver/SQLGetInfo.c
@@ -1688,6 +1688,7 @@ SQLGetInfoW(SQLHDBC ConnectionHandle,
if (ptr != InfoValuePtr) {
if (rc == SQL_SUCCESS_WITH_INFO) {
clearDbcErrors(dbc);
+ free(ptr);
ptr = malloc(++n); /* add one for NULL byte */
if (ptr == NULL) {
/* Memory allocation error */
diff --git a/clients/odbc/driver/SQLGetStmtAttr.c
b/clients/odbc/driver/SQLGetStmtAttr.c
--- a/clients/odbc/driver/SQLGetStmtAttr.c
+++ b/clients/odbc/driver/SQLGetStmtAttr.c
@@ -52,12 +52,16 @@ MNDBGetStmtAttr(ODBCStmt *stmt,
* StringLengthPtr */
switch (Attribute) {
+#ifndef STATIC_CODE_ANALYSIS
+ /* Coverity doesn't like the debug print in WriteData, so we
+ * hide this whole thing */
case SQL_ATTR_APP_PARAM_DESC: /* SQLHANDLE */
WriteData(ValuePtr, stmt->ApplParamDescr, SQLHANDLE);
return SQL_SUCCESS;
case SQL_ATTR_APP_ROW_DESC: /* SQLHANDLE */
WriteData(ValuePtr, stmt->ApplRowDescr, SQLHANDLE);
return SQL_SUCCESS;
+#endif
case SQL_ATTR_ASYNC_ENABLE: /* SQLULEN */
/* SQL_ASYNC_ENABLE */
WriteData(ValuePtr, SQL_ASYNC_ENABLE_OFF, SQLULEN);
@@ -76,12 +80,16 @@ MNDBGetStmtAttr(ODBCStmt *stmt,
/* SQL_CURSOR_TYPE */
WriteData(ValuePtr, stmt->cursorType, SQLULEN);
break;
+#ifndef STATIC_CODE_ANALYSIS
+ /* Coverity doesn't like the debug print in WriteData, so we
+ * hide this whole thing */
case SQL_ATTR_IMP_PARAM_DESC: /* SQLHANDLE */
WriteData(ValuePtr, stmt->ImplParamDescr, SQLHANDLE);
return SQL_SUCCESS;
case SQL_ATTR_IMP_ROW_DESC: /* SQLHANDLE */
WriteData(ValuePtr, stmt->ImplRowDescr, SQLHANDLE);
return SQL_SUCCESS;
+#endif
case SQL_ATTR_MAX_LENGTH: /* SQLULEN */
/* SQL_MAX_LENGTH */
WriteData(ValuePtr, 0, SQLULEN);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1504,7 +1504,7 @@ BBPdir(int cnt, bat *subcommit)
}
if (fclose(fp) == EOF) {
GDKsyserror("BBPdir: Closing BBP.dir file failed\n");
- goto bailout;
+ return -1;
}
IODEBUG fprintf(stderr, "#BBPdir end\n");
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -446,7 +446,13 @@ GDKload(int farmid, const char *nme, con
* only accepts int */
for (n_expected = (ssize_t) size; n_expected >
0; n_expected -= n) {
n = read(fd, dst, (unsigned) MIN(1 <<
30, n_expected));
+#ifndef STATIC_CODE_ANALYSIS
+ /* Coverity doesn't seem to
+ * recognize that we're just
+ * printing the value of ptr,
+ * not its contents */
IODEBUG fprintf(stderr, "#read(dst "
PTRFMT ", n_expected " SSZFMT ", fd %d) = " SSZFMT "\n", PTRFMTCAST(void *)dst,
n_expected, fd, n);
+#endif
if (n <= 0)
break;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list