Changeset: cec6ceb82f7a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cec6ceb82f7a
Modified Files:
        monetdb5/mal/mal_authorize.c
        monetdb5/mal/mal_prelude.c
        monetdb5/mal/mal_profiler.c
        monetdb5/modules/kernel/batmmath.c
        monetdb5/modules/kernel/batstr.c
        monetdb5/modules/mal/remote.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_cat.c
        sql/include/sql_catalog.h
        sql/server/rel_optimizer.c
        sql/server/rel_schema.c
        sql/server/rel_select.c
        sql/server/rel_updates.c
        sql/storage/store.c
        tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Oct2020


diffs (truncated from 2896 to 300 lines):

diff --git a/buildtools/coverity_model.c b/buildtools/coverity_model.c
new file mode 100644
--- /dev/null
+++ b/buildtools/coverity_model.c
@@ -0,0 +1,166 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
+ */
+
+/*
+ * This file contains a model for Coverity Scan.
+ * This file is not a normal source file.  It is not compiled by any
+ * compiler, but instead it is uploaded to the Coverity site and used
+ * during any analysis they do on our code.
+ *
+ * We model our use of the various allocation functions.
+ * Things we want to do is model that GDKmalloc and friends are paired
+ * with GDKfree, and that exceptions created by createException and
+ * createMalException should be freed with freeException.
+ *
+ * author: Sjoerd Mullender
+ */
+
+typedef enum { GDK_FAIL, GDK_SUCCEED } gdk_return;
+typedef struct {} *MalBlkPtr;
+
+void
+GDKfree(void *blk)
+{
+       if (blk) {
+               __coverity_free__(blk);
+               __coverity_mark_as_afm_freed__(blk, "GDKfree");
+       }
+}
+
+void *
+GDKmalloc(size_t size)
+{
+       int has_memory;
+       __coverity_negative_sink__(size);
+       if(has_memory) {
+               void *p = __coverity_alloc__(size);
+               __coverity_mark_as_afm_allocated__(p, "GDKfree");
+               __coverity_mark_as_uninitialized_buffer__(p);
+               return p;
+       }
+       return 0;
+}
+
+void *
+GDKzalloc(size_t size)
+{
+       void *p = GDKmalloc(size);
+       if (p) {
+               for (size_t i = 0; i < size; i++)
+                       ((char *) p)[i] = 0;
+       }
+       return p;
+}
+
+char *
+GDKstrdup(const char *s)
+{
+       char *p;
+       size_t i;
+       int has_memory;
+       if (s == 0)
+               return 0;
+       __coverity_string_null_sink__(s);
+       __coverity_string_size_sink__(s);
+       if (has_memory) {
+               p = __coverity_alloc_nosize__();
+               __coverity_mark_as_afm_allocated__(p, "GDKfree");
+               for (i = 0; (p[i] = s[i]); i++)
+                       ;
+               return p;
+       }
+       return 0;
+}
+
+char *
+GDKstrndup(const char *s, size_t size)
+{
+       char *p;
+       size_t i;
+       __coverity_negative_sink__(size);
+       if (s == 0)
+               return 0;
+       p = GDKmalloc(size + 1);
+       if (p) {
+               for (i = 0; i < size && (p[i] = s[i]); i++)
+                       ;
+               p[i] = 0;
+       }
+       return p;
+}
+
+void *
+GDKrealloc(void *blk, size_t size)
+{
+       void *p = GDKmalloc(size);
+       if (p != 0)
+               GDKfree(blk);
+       return p;
+}
+
+void *
+GDKmmap(const char *path, int mode, size_t size)
+{
+       int has_memory;
+       __coverity_negative_sink__(size);
+       if (has_memory) {
+               void *p = __coverity_alloc__(size);
+               __coverity_mark_as_afm_allocated__(p, "GDKmunmap");
+               __coverity_writeall__(p);
+               return p;
+       }
+       return 0;
+}
+
+gdk_return
+GDKmunmap(void *p, size_t size)
+{
+       int failed;
+       __coverity_free__(p);
+       __coverity_mark_as_afm_freed__(p, "GDKmunmap");
+       return failed ? GDK_FAIL : GDK_SUCCEED;
+}
+
+void *
+GDKmremap(const char *path, int mode, void *old_address, size_t old_size, 
size_t *new_size)
+{
+       void *p = GDKmmap(path, mode, new_size);
+       if (p) {
+               (void) GDKmunmap(old_address, old_size);
+       }
+       return p;
+}
+
+char *
+createException(enum malexception type, const char *fcn, const char *format, 
...)
+{
+       char *p;
+       __coverity_format_string_sink__(format);
+       p = __coverity_alloc_nosize__();
+       __coverity_mark_as_afm_allocated__(p, "freeException");
+       return p;
+}
+
+char *
+createMalException(MalBlkPtr mb, int pc, enum malexception type, const char 
*format, ...)
+{
+       char *p;
+       __coverity_format_string_sink__(format);
+       p = __coverity_alloc_nosize__();
+       __coverity_mark_as_afm_allocated__(p, "freeException");
+       return p;
+}
+
+void
+freeException(char *p)
+{
+       if (p) {
+               __coverity_free__(p);
+               __coverity_mark_as_afm_freed__(p, "freeException");
+       }
+}
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -1066,7 +1066,7 @@ AUTHaddRemoteTableCredentials(const char
 {
        char *pwhash = NULL;
        bool free_pw = false;
-       str tmp, output = MAL_SUCCEED;
+       str output = MAL_SUCCEED;
        BUN p;
        str msg = MAL_SUCCEED;
 
@@ -1151,14 +1151,14 @@ AUTHaddRemoteTableCredentials(const char
        msg = AUTHverifyPassword(pwhash);
        if( msg != MAL_SUCCEED){
                free(pwhash);
-               rethrow("addRemoteTableCredentials", tmp, msg);
+               return msg;
        }
 
        str cypher;
        msg = AUTHcypherValue(&cypher, pwhash);
        if( msg != MAL_SUCCEED){
                free(pwhash);
-               rethrow("addRemoteTableCredentials", tmp, msg);
+               return msg;
        }
 
        /* Add entry */
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -538,9 +538,11 @@ pushStr(MalBlkPtr mb, InstrPtr q, const 
        if (q == NULL)
                return NULL;
        cst.vtype= TYPE_str;
-       if ((cst.val.sval= GDKstrdup(Val)) == NULL)
-               addMalException(mb, createException(MAL, "pushStr", "Can not 
allocate string variable"));
-       else{
+       if ((cst.val.sval= GDKstrdup(Val)) == NULL) {
+               str msg = createException(MAL, "pushStr", "Can not allocate 
string variable");
+               addMalException(mb, msg);
+               freeException(msg);
+       } else{
                cst.len = strlen(cst.val.sval);
                _t = defConstant(mb,TYPE_str,&cst);
                if( _t >= 0)
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -71,7 +71,10 @@ MCinit(void)
                maxclients = atoi(max_clients);
        if (maxclients <= 0) {
                maxclients = 64;
-               GDKsetenv("max_clients", "64");
+               if (GDKsetenv("max_clients", "64") != GDK_SUCCEED) {
+                       TRC_CRITICAL(MAL_SERVER, "Initialization failed: " 
MAL_MALLOC_FAIL "\n");
+                       return false;
+               }
        }
 
        MAL_MAXCLIENTS = /* client connections */ maxclients;
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -93,6 +93,8 @@ createExceptionInternal(enum malexceptio
                msg = M5OutOfMemory;
        }
        va_end(ap2);
+
+       assert(msg);
        return msg;
 }
 
@@ -121,6 +123,7 @@ createException(enum malexception type, 
                 * reported */
                ret = createException(type, fcn, SQLSTATE(HY013) 
MAL_MALLOC_FAIL ": %s", GDKerrbuf);
                GDKclrerr();
+               assert(ret);
                return ret;
        }
        if (strcmp(format, GDK_EXCEPTION) == 0 && GDKerrbuf[0]) {
@@ -137,6 +140,7 @@ createException(enum malexception type, 
                if (ret == NULL)
                        ret = createException(type, fcn, "GDK reported error: 
%s", p);
                GDKclrerr();
+               assert(ret);
                return ret;
        }
        va_start(ap, format);
@@ -144,6 +148,7 @@ createException(enum malexception type, 
        va_end(ap);
        GDKclrerr();
 
+       assert(ret);
        return ret;
 }
 
diff --git a/monetdb5/mal/mal_exception.h b/monetdb5/mal/mal_exception.h
--- a/monetdb5/mal/mal_exception.h
+++ b/monetdb5/mal/mal_exception.h
@@ -34,7 +34,7 @@ enum malexception {
 #define throw \
        return createException
 #define rethrow(FCN, TMP, PRV) \
-       {if ((TMP = PRV) != MAL_SUCCEED) return(TMP);}
+       do { if ((TMP = (PRV)) != MAL_SUCCEED) return(TMP); } while(0)
 
 #if !__has_attribute(__returns_nonnull__)
 #define __returns_nonnull__
diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c
--- a/monetdb5/mal/mal_module.c
+++ b/monetdb5/mal/mal_module.c
@@ -42,8 +42,8 @@ findFunctionImplementation(const char *c
                                Symbol s;
                                if ((s = moduleIndex[i]->space[j]) != NULL) {
                                        do {
-                                               if (strcmp(s->def->binding, 
cname) == 0 &&
-                                                       s->def &&
+                                               if (s->def &&
+                                                       strcmp(s->def->binding, 
cname) == 0 &&
                                                        s->def->stmt &&
                                                        s->def->stmt[0] &&
                                                        s->def->stmt[0]->fcn) {
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -1457,7 +1457,7 @@ parseEnd(Client cntxt)
                        cntxt->curprg->def->errors=0;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to