Changeset: 392795a36b72 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/392795a36b72
Modified Files:
        clients/mapiclient/dump.c
        clients/mapilib/mapi.c
        gdk/gdk_batop.c
        gdk/gdk_cand.c
        geom/monetdb5/geomBulk.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_session.c
Branch: Aug2024
Log Message:

Various Coverity-inspired fixes.


diffs (180 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -2251,14 +2251,10 @@ dump_table(Mapi mid, const char *schema,
                                goto doreturn;
                        }
                        for (int64_t i = 0; i < rows; i++) {
-                               if (mapi_fetch_row(hdl) == 0) {
-                                       mapi_close_handle(hdl);
-                                       fprintf(stderr, "unexepcted error\n");
-                                       goto doreturn;
-                               }
-                               tables[i].schema = strdup(mapi_fetch_field(hdl, 
0));
-                               tables[i].table = strdup(mapi_fetch_field(hdl, 
1));
-                               if (tables[i].schema == NULL || tables[i].table 
== NULL) {
+                               tables[i].schema = tables[i].table = NULL;
+                               if (mapi_fetch_row(hdl) == 0 ||
+                                       (tables[i].schema = 
strdup(mapi_fetch_field(hdl, 0))) == NULL ||
+                                       (tables[i].table = 
strdup(mapi_fetch_field(hdl, 1))) == NULL) {
                                        do {
                                                free(tables[i].schema);
                                                free(tables[i].table);
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1786,12 +1786,6 @@ mapi_new(msettings *settings)
        mid = malloc(sizeof(*mid));
        if (mid == NULL)
                return NULL;
-       if (settings == NULL)
-               settings = msettings_create();
-       if (settings == NULL) {
-               free(mid);
-               return NULL;
-       }
 
        /* then fill in some details */
        *mid = MapiStructDefaults;
@@ -1800,6 +1794,13 @@ mapi_new(msettings *settings)
                mapi_destroy(mid);
                return NULL;
        }
+       if (settings == NULL) {
+               settings = msettings_create();
+               if (settings == NULL) {
+                       mapi_destroy(mid);
+                       return NULL;
+               }
+       }
        mid->settings = settings;
        mid->blk.buf[0] = 0;
        mid->blk.buf[mid->blk.lim] = 0;
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -3066,9 +3066,11 @@ BATcount_no_nil(BAT *b, BAT *s)
 
        hseq = b->hseqbase;
        canditer_init(&ci, b, s);
-       if (b->tnonil)
+       BATiter bi = bat_iterator(b);
+       if (bi.nonil) {
+               bat_iterator_end(&bi);
                return ci.ncand;
-       BATiter bi = bat_iterator(b);
+       }
        p = bi.base;
        t = ATOMbasetype(bi.type);
        switch (t) {
diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c
--- a/gdk/gdk_cand.c
+++ b/gdk/gdk_cand.c
@@ -846,6 +846,7 @@ canditer_mask_next(const struct canditer
                                o = 31;
                                if (p == 0)
                                        return oid_nil;
+                               p--;
                        } else {
                                o--;
                        }
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -823,10 +823,10 @@ wkbTransform_bat_cand(bat *outBAT_id, ba
                        GEOSSetSRID_r(geoshandle, transformedGeosGeometry, 
*srid_dst);
                        /* get the wkb */
                        if ((transformedWKB = 
geos2wkb(transformedGeosGeometry)) == NULL)
-                               throw(MAL, "batgeom.Transform", SQLSTATE(38000) 
"Geos operation geos2wkb failed");
+                               err = createException(MAL, "batgeom.Transform", 
SQLSTATE(38000) "Geos operation geos2wkb failed");
                        else {
                                if (BUNappend(outBAT, transformedWKB, false) != 
GDK_SUCCEED) {
-                                       throw(MAL, "batgeom.Transform", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                                       err = createException(MAL, 
"batgeom.Transform", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                                }
                        }
 
@@ -842,10 +842,14 @@ wkbTransform_bat_cand(bat *outBAT_id, ba
        BBPunfix(inBAT->batCacheid);
        if (s)
                BBPunfix(s->batCacheid);
-       *outBAT_id = outBAT->batCacheid;
-       BBPkeepref(outBAT);
+       if (err) {
+               BBPreclaim(outBAT);
+       } else {
+               *outBAT_id = outBAT->batCacheid;
+               BBPkeepref(outBAT);
+       }
 
-       return MAL_SUCCEED;
+       return err;
 #endif
 }
 
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
@@ -184,12 +184,12 @@ MCgetClient(int id)
 static void
 MCresetProfiler(stream *fdout)
 {
-       if (fdout != maleventstream)
-               return;
        MT_lock_set(&mal_profileLock);
-       maleventstream = NULL;
-       profilerStatus = 0;
-       profilerMode = 0;
+       if (fdout == maleventstream) {
+               maleventstream = NULL;
+               profilerStatus = 0;
+               profilerMode = 0;
+       }
        MT_lock_unset(&mal_profileLock);
 }
 
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -571,6 +571,9 @@ runMALsequence(Client cntxt, MalBlkPtr m
                        break;
                }
 
+               freeException(ret);
+               ret = MAL_SUCCEED;
+
                if (stk->status) {
                        /* pause procedure from SYSMON */
                        if (stk->status == 'p') {
@@ -661,8 +664,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
                        }
                }
 
-               freeException(ret);
-               ret = MAL_SUCCEED;
                switch (pci->token) {
                case ASSIGNsymbol:
                        /* Assignment command
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -614,16 +614,13 @@ MALreader(Client c)
  * the estimate is more expensive than just counting the lines.
  */
 static int
-prepareMalBlk(MalBlkPtr mb, str s)
+prepareMalBlk(MalBlkPtr mb, const char *s)
 {
        int cnt = STMT_INCREMENT;
 
-       while (s) {
-               s = strchr(s, '\n');
-               if (s) {
-                       s++;
+       if (s && *s) {
+               while ((s = strchr(s + 1, '\n')) != NULL)
                        cnt++;
-               }
        }
        cnt = (int) (cnt * 1.1);
        return resizeMalBlk(mb, cnt);
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to