Changeset: f3d0a4fdb80a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f3d0a4fdb80a
Modified Files:
clients/odbc/driver/SQLPrepare.c
gdk/gdk_logger.c
monetdb5/extras/rapi/converters.c.h
sql/backends/monet5/UDF/pyapi/pyheader.h
testing/difflib.c
tools/merovingian/utils/utils.c
Branch: Nov2019
Log Message:
Coverity fixes.
diffs (178 lines):
diff --git a/clients/odbc/driver/SQLPrepare.c b/clients/odbc/driver/SQLPrepare.c
--- a/clients/odbc/driver/SQLPrepare.c
+++ b/clients/odbc/driver/SQLPrepare.c
@@ -135,7 +135,11 @@ MNDBPrepare(ODBCStmt *stmt,
int concise_type;
int length, scale;
- mapi_fetch_row(hdl);
+ if (mapi_fetch_row(hdl) == 0) {
+ /* Memory allocation error (or maybe something else) */
+ addStmtError(stmt, "HY001", 0, 0);
+ return SQL_ERROR;
+ }
if (ncols == 3 ||
(s = mapi_fetch_field(hdl, 5)) == NULL) {
/* either old prepare (i.e. old server) or no
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1073,7 +1073,7 @@ logger_open(logger *lg)
return GDK_SUCCEED;
}
-static void
+static inline void
logger_close(logger *lg)
{
if (!lg->inmemory)
@@ -1103,8 +1103,7 @@ logger_readlog(logger *lg, char *filenam
/* if the file doesn't exist, there is nothing to be read back */
if (lg->log == NULL || mnstr_errnr(lg->log)) {
- close_stream(lg->log);
- lg->log = NULL;
+ logger_close(lg);
GDKdebug = dbg;
*filemissing = true;
return GDK_SUCCEED;
@@ -1112,13 +1111,14 @@ logger_readlog(logger *lg, char *filenam
short byteorder;
switch (mnstr_read(lg->log, &byteorder, sizeof(byteorder), 1)) {
case -1:
- close_stream(lg->log);
- lg->log = NULL;
+ logger_close(lg);
GDKdebug = dbg;
return GDK_FAIL;
case 0:
/* empty file is ok */
- break;
+ logger_close(lg);
+ GDKdebug = dbg;
+ return GDK_SUCCEED;
case 1:
/* if not empty, must start with correct byte order mark */
assert(byteorder == 1234);
@@ -1126,8 +1126,7 @@ logger_readlog(logger *lg, char *filenam
}
if ((fd = getFileNo(lg->log)) < 0 || fstat(fd, &sb) < 0) {
fprintf(stderr, "!ERROR: logger_readlog: fstat on opened file
%s failed\n", filename);
- close_stream(lg->log);
- lg->log = NULL;
+ logger_close(lg);
GDKdebug = dbg;
/* If the file could be opened, but fstat fails,
* something weird is going on */
diff --git a/monetdb5/extras/rapi/converters.c.h
b/monetdb5/extras/rapi/converters.c.h
--- a/monetdb5/extras/rapi/converters.c.h
+++ b/monetdb5/extras/rapi/converters.c.h
@@ -284,12 +284,12 @@ static BAT* sexp_to_bat(SEXP s, int type
b->tnonil = false;
if (BUNappend(b, str_nil, false) !=
GDK_SUCCEED) {
BBPreclaim(b);
- b = NULL;
+ return NULL;
}
} else {
if (BUNappend(b, CHAR(rse), false) !=
GDK_SUCCEED) {
BBPreclaim(b);
- b = NULL;
+ return NULL;
}
}
}
diff --git a/sql/backends/monet5/UDF/pyapi/pyheader.h
b/sql/backends/monet5/UDF/pyapi/pyheader.h
--- a/sql/backends/monet5/UDF/pyapi/pyheader.h
+++ b/sql/backends/monet5/UDF/pyapi/pyheader.h
@@ -46,6 +46,9 @@
#endif
// Numpy Library
+#ifdef STATIC_CODE_ANALYSIS
+#define _NPY_NO_DEPRECATIONS
+#endif
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#define NPY_INTERNAL_BUILD 0
#ifdef __INTEL_COMPILER
diff --git a/testing/difflib.c b/testing/difflib.c
--- a/testing/difflib.c
+++ b/testing/difflib.c
@@ -49,7 +49,11 @@
#define UNLINK(x)
#define ERRHNDL(r,s,t,u) ErrXit(s,t,u)
#else
+#ifdef STATIC_CODE_ANALYSIS
+#define UNLINK(x)
+#else
#define UNLINK(x) remove(x)
+#endif
#define ERRHNDL(r,s,t,u) return r
#endif
@@ -183,6 +187,9 @@ lw_diff2wc_diff(int mindiff, int doChar,
TRACE(fprintf(STDERR, "lw_diff2wc_diff(%i,%i,%s,%s)\n", mindiff,
doChar, lw_diff_fn, wc_diff_fn));
lw_diff_fp = Rfopen(lw_diff_fn);
+ if (lw_diff_fp == NULL) {
+ ERRHNDL(0, "cannot open file in lw_diff2wc_diff:", lw_diff_fn,
1);
+ }
if (!(ok = fgets(line, BUFLEN, lw_diff_fp))) {
fclose(lw_diff_fp);
ERRHNDL(0, "empty file in lw_diff2wc_diff:", lw_diff_fn, 1);
@@ -497,6 +504,7 @@ lwc_diff2html(char *old_fn, char *new_fn
fprintf(html_fp, "<!--NoDiffs-->\n");
fflush(html_fp);
fclose(html_fp);
+ fclose(lwc_diff_fp);
return 0;
}
@@ -519,15 +527,27 @@ lwc_diff2html(char *old_fn, char *new_fn
line[strlen(line) - 1] = '\0';
while (ok && strncmp(line, "@@ -", 4)) {
- if (!strncmp(line, "--- ", 4))
+ if (!strncmp(line, "--- ", 4)) {
+ if (old) {
+ fprintf(stderr, "syntax error\n");
+ exit(1);
+ }
old = strdup(line + 4);
- else if (!strncmp(line, "+++ ", 4))
+ } else if (!strncmp(line, "+++ ", 4)) {
+ if (new) {
+ fprintf(stderr, "syntax error\n");
+ exit(1);
+ }
new = strdup(line + 4);
- else
+ } else
fprintf(html_fp, "<tbody><tr><td
colspan='7'>%s</td></tr></tbody>\n", HTMLsave(line));
ok = fgets(line, BUFLEN, lwc_diff_fp);
line[strlen(line) - 1] = '\0';
}
+ if (old == NULL || new == NULL) {
+ fprintf(stderr, "syntax or malloc error\n");
+ exit(1);
+ }
old_time = strchr(old, '\t');
*old_time++ = '\0';
new_time = strchr(new, '\t');
diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c
--- a/tools/merovingian/utils/utils.c
+++ b/tools/merovingian/utils/utils.c
@@ -446,7 +446,12 @@ generatePassphraseFile(const char *path)
/* delete such that we are sure we recreate the file with restricted
* permissions */
- remove(path);
+ if (remove(path) == -1 && errno != ENOENT) {
+ char err[512];
+ snprintf(err, sizeof(err), "unable to remove '%s': %s",
+ path, strerror(errno));
+ return(strdup(err));
+ }
if ((fd = open(path, O_CREAT | O_WRONLY | O_CLOEXEC, S_IRUSR |
S_IWUSR)) == -1) {
char err[512];
snprintf(err, sizeof(err), "unable to open '%s': %s",
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list