Changeset: cba9758e6ba1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cba9758e6ba1
Modified Files:
        monetdb5/mal/mal_authorize.c
        monetdb5/mal/mal_builder.c
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_exception.h
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_profiler.c
        monetdb5/modules/mal/remote.c
        monetdb5/modules/mal/tracer.c
        monetdb5/optimizer/opt_mergetable.c
        tools/monetdbe/monetdbe.c
Branch: Oct2020
Log Message:

Coverity.


diffs (truncated from 396 to 300 lines):

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
@@ -1160,14 +1160,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_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_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;
                } else if (cntxt->curprg->def->errors) {
                        //collect all errors for reporting
-                       str new = GDKzalloc(strlen(errors) + 
strlen(cntxt->curprg->def->errors) +16);
+                       str new = GDKmalloc(strlen(errors) + 
strlen(cntxt->curprg->def->errors) +16);
                        if (new){
                                strcpy(new, errors);
                                if( new[strlen(new)-1] != '\n')
@@ -1478,14 +1478,23 @@ parseEnd(Client cntxt)
                        cntxt->backup = 0;
                } else {
                        str msg;
-                       if((msg = 
MSinitClientPrg(cntxt,cntxt->curmodule->name,"main")) != MAL_SUCCEED) {
-                               if(!msg){
+                       if ((msg = 
MSinitClientPrg(cntxt,cntxt->curmodule->name,"main")) != MAL_SUCCEED) {
+                               if (errors) {
+                                       str new = GDKmalloc(strlen(errors) + 
strlen(msg) + 3);
+                                       if (new) {
+                                               strcpy(new, msg);
+                                               if (new[strlen(new) - 1] != 
'\n')
+                                                       strcat(new, "\n");
+                                               strcat(new, errors);
+                                               freeException(errors);
+                                               cntxt->curprg->def->errors = 
new;
+                                       } else {
+                                               cntxt->curprg->def->errors = 
errors;
+                                       }
+                                       freeException(msg);
+                               } else {
                                        cntxt->curprg->def->errors = msg;
-                                       GDKfree(errors);
-                               } else if(!errors){
-                                       cntxt->curprg->def->errors = errors;
-                               } else
-                                       freeException(msg);
+                               }
                                return 1;
                        }
                }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -344,7 +344,8 @@ renderProfilerEvent(Client cntxt, MalBlk
                                                return;
                                        cv = 
VALformat(&stk->stk[getArg(pci,j)]);
                                        c = strchr(cv, '>');
-                                       *c = 0;
+                                       if (c)          /* unlikely that this 
isn't true */
+                                               *c = 0;
                                        ok = logadd(&logbuf, 
",\"file\":\"%s\"", cv + 1);
                                        GDKfree(cv);
                                        if (!ok)
@@ -679,8 +680,10 @@ stopProfiler(Client cntxt)
 static void
 _cleanupProfiler(Client cntxt)
 {
-       BBPunfix(cntxt->profticks->batCacheid);
-       BBPunfix(cntxt->profstmt->batCacheid);
+       if (cntxt->profticks)
+               BBPunfix(cntxt->profticks->batCacheid);
+       if (cntxt->profstmt)
+               BBPunfix(cntxt->profstmt->batCacheid);
        cntxt->profticks = cntxt->profstmt = NULL;
 }
 
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -974,6 +974,8 @@ static str RMTregisterInternal(Client cn
        msg = chkProgram(cntxt->usermodule, sym->def);
        if ( msg == MAL_SUCCEED || sym->def->errors) {
                MT_lock_unset(&c->lock);
+               if (msg)
+                       return msg;
                throw(MAL, "remote.register",
                                "function '%s.%s' contains syntax or type 
errors",
                                mod, fcn);
diff --git a/monetdb5/modules/mal/tracer.c b/monetdb5/modules/mal/tracer.c
--- a/monetdb5/modules/mal/tracer.c
+++ b/monetdb5/modules/mal/tracer.c
@@ -32,7 +32,7 @@ TRACERset_component_level(void *ret, str
 {
     (void) ret;
     if (GDKtracer_set_component_level(*comp_id, *lvl_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT);
+        throw(MAL, "logging.setcomplevel", ILLEGAL_ARGUMENT);
 
     return MAL_SUCCEED;
 }
@@ -43,7 +43,7 @@ TRACERreset_component_level(void *ret, s
 {
     (void) ret;
     if (GDKtracer_reset_component_level(*comp_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT"\n");
+        throw(MAL, "logging.resetcomplevel", ILLEGAL_ARGUMENT"\n");
 
     return MAL_SUCCEED;
 }
@@ -54,7 +54,7 @@ TRACERset_layer_level(void *ret, str *la
 {
     (void) ret;
     if (GDKtracer_set_layer_level(*layer_id, *lvl_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT"\n");
+        throw(MAL, "logging.setlayerlevel", ILLEGAL_ARGUMENT"\n");
 
     return MAL_SUCCEED;
 }
@@ -65,7 +65,7 @@ TRACERreset_layer_level(void *ret, str *
 {
     (void) ret;
     if (GDKtracer_reset_layer_level(*layer_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT"\n");
+        throw(MAL, "logging.resetlayerlevel", ILLEGAL_ARGUMENT"\n");
 
     return MAL_SUCCEED;
 }
@@ -76,7 +76,7 @@ TRACERset_flush_level(void *ret, str *lv
 {
     (void) ret;
     if (GDKtracer_set_flush_level(*lvl_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT"\n");
+        throw(MAL, "logging.setflushlevel", ILLEGAL_ARGUMENT"\n");
 
     return MAL_SUCCEED;
 }
@@ -87,7 +87,7 @@ TRACERreset_flush_level(void *ret)
 {
     (void) ret;
     if (GDKtracer_reset_flush_level() != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, _OPERATION_FAILED"\n");
+        throw(MAL, "logging.resetflushlevel", _OPERATION_FAILED"\n");
 
     return MAL_SUCCEED;
 }
@@ -98,7 +98,7 @@ TRACERset_adapter(void *ret, str *adapte
 {
     (void) ret;
     if (GDKtracer_set_adapter(*adapter_id) != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, ILLEGAL_ARGUMENT"\n");
+        throw(MAL, "logging.setadapter", ILLEGAL_ARGUMENT"\n");
 
     return MAL_SUCCEED;
 }
@@ -109,7 +109,7 @@ TRACERreset_adapter(void *ret)
 {
     (void) ret;
     if (GDKtracer_reset_adapter() != GDK_SUCCEED)
-        throw(MAL, __FUNCTION__, _OPERATION_FAILED"\n");
+        throw(MAL, "logging.resetadapter", _OPERATION_FAILED"\n");
 
     return MAL_SUCCEED;
 }
@@ -125,37 +125,33 @@ TRACERcomp_info(Client cntxt, MalBlkPtr 
     bat *i = getArgReference_bat(stk, pci, 0);
     bat *c = getArgReference_bat(stk, pci, 1);
     bat *l = getArgReference_bat(stk, pci, 2);
-    str msg = MAL_SUCCEED;
 
     id = COLnew(0, TYPE_int, (BUN) COMPONENTS_COUNT, TRANSIENT);
     component = COLnew(0, TYPE_str, (BUN) COMPONENTS_COUNT, TRANSIENT);
     log_level = COLnew(0, TYPE_str, (BUN) COMPONENTS_COUNT, TRANSIENT);
 
-    if ( id == NULL || component == NULL || log_level == NULL )
-    {
-        BBPreclaim(id);
-        BBPreclaim(component);
-        BBPreclaim(log_level);
-        throw(MAL, __FUNCTION__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
-    }
+    if ( id == NULL || component == NULL || log_level == NULL ) {
+               BBPreclaim(id);
+               BBPreclaim(component);
+               BBPreclaim(log_level);
+               throw(MAL, "logging.compinfo", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
 
     // Fill the BATs
     MT_lock_set(&mal_delayLock);
-        if(GDKtracer_fill_comp_info(id, component, log_level) == GDK_FAIL)
-            goto bailout;
+       if(GDKtracer_fill_comp_info(id, component, log_level) == GDK_FAIL) {
+               MT_lock_unset(&mal_delayLock);
+               BBPunfix(id->batCacheid);
+               BBPunfix(component->batCacheid);
+               BBPunfix(log_level->batCacheid);
+               throw(MAL, "logging.compinfo", GDK_EXCEPTION);
+       }
     MT_lock_unset(&mal_delayLock);
 
     BBPkeepref(*i = id->batCacheid);
     BBPkeepref(*c = component->batCacheid);
     BBPkeepref(*l = log_level->batCacheid);
     return MAL_SUCCEED;
-
-    bailout:
-        MT_lock_unset(&mal_delayLock);
-        BBPunfix(id->batCacheid);
-        BBPunfix(component->batCacheid);
-        BBPunfix(log_level->batCacheid);
-        return msg ? msg : createException(MAL, __FUNCTION__, SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
 }
 
 #include "mel.h"
diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -1937,8 +1937,8 @@ mat_sample(MalBlkPtr mb, InstrPtr p, mat
 
        r = newInstruction(mb, algebraRef, projectionRef);
        getArg(r,0) = getArg(p,0);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to