Changeset: 34cfecee891f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=34cfecee891f
Modified Files:
        clients/mapiclient/mclient.c
        clients/mapilib/mapi.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_logger.c
        sql/backends/monet5/bam/bam_loader.c
Branch: Oct2014
Log Message:

Coverity-inspired fixes.


diffs (167 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1819,6 +1819,7 @@ doFileBulk(Mapi mid, FILE *fp)
                        }
                        if (hdl == NULL)
                                break;  /* nothing more to do */
+                       buf[0] = 0;
                } else {
                        if (first &&
                            length >= UTF8BOMLENGTH &&
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1501,6 +1501,8 @@ new_result(MapiHdl hdl)
                printf("allocating new result set\n");
        /* append a newly allocated struct to the end of the linked list */
        result = malloc(sizeof(*result));
+       if (result == NULL)
+               return NULL;
        result->next = NULL;
        if (hdl->lastresult == NULL)
                hdl->result = hdl->lastresult = result;
@@ -1746,7 +1748,6 @@ mapi_new_handle(Mapi mid)
        mapi_check0(mid, "mapi_new_handle");
 
        hdl = malloc(sizeof(*hdl));
-       assert(hdl);
        if (hdl == NULL) {
                mapi_setError(mid, "Memory allocation failure", 
"mapi_new_handle", MERROR);
                return NULL;
@@ -1904,6 +1905,10 @@ mapi_new(void)
        mid->tracelog = NULL;
        mid->blk.eos = 0;
        mid->blk.buf = malloc(BLOCK + 1);
+       if (mid->blk.buf == NULL) {
+               mapi_destroy(mid);
+               return NULL;
+       }
        mid->blk.buf[BLOCK] = 0;
        mid->blk.buf[0] = 0;
        mid->blk.nxt = 0;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -247,10 +247,12 @@ BATnewstorage(int ht, int tt, BUN cap, i
        BATstore *bs;
        BAT *bn;
 
-       assert(cap <= BUN_MAX);
        /* and in case we don't have assertions enabled: limit the size */
-       if (cap > BUN_MAX)
+       if (cap > BUN_MAX) {
+               /* shouldn't happen, but if it does... */
+               assert(0);
                cap = BUN_MAX;
+       }
        bs = BATcreatedesc(ht, tt, (ht || tt), role);
        if (bs == NULL)
                return NULL;
@@ -3009,9 +3011,10 @@ BATderiveHeadProps(BAT *b, int expensive
        BUN hb, prb;
        oid sqbs = oid_nil;
 
-       assert(b != NULL);
-       if (b == NULL)
+       if (b == NULL) {
+               assert(0);
                return;
+       }
        assert((b->hkey & BOUND2BTRUE) == 0);
        COLsettrivprop(b, b->H);
        cmpf = ATOMcompare(b->htype);
@@ -3204,10 +3207,10 @@ BATderiveHeadProps(BAT *b, int expensive
 void
 BATderiveProps(BAT *b, int expensive)
 {
-       assert(b != NULL);
-
-       if (b == NULL)
+       if (b == NULL) {
+               assert(0);
                return;
+       }
        BATderiveHeadProps(b, expensive);
        if (b->H != b->T)
                BATderiveHeadProps(BATmirror(b), expensive);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1295,7 +1295,7 @@ gdk_return
 BATsubsort(BAT **sorted, BAT **order, BAT **groups,
           BAT *b, BAT *o, BAT *g, int reverse, int stable)
 {
-       BAT *bn = NULL, *on = NULL, *gn = NULL;
+       BAT *bn = NULL, *on = NULL, *gn;
        oid *restrict grps, prev;
        BUN p, q, r;
 
@@ -1522,8 +1522,6 @@ BATsubsort(BAT **sorted, BAT **order, BA
                BBPunfix(bn->batCacheid);
        if (on)
                BBPreclaim(on);
-       if (gn)
-               BBPreclaim(gn);
        if (sorted)
                *sorted = NULL;
        if (order)
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1530,6 +1530,7 @@ logger_exit(logger *lg)
                char ext[BUFSIZ];
 
                if (fprintf(fp, "%06d\n\n", lg->version) < 0) {
+                       (void) fclose(fp);
                        fprintf(stderr, "!ERROR: logger_exit: write to %s 
failed\n",
                                filename);
                        return LOG_ERR;
@@ -1537,13 +1538,20 @@ logger_exit(logger *lg)
                lg->id ++;
 
                if (logger_commit(lg) != LOG_OK) {
+                       (void) fclose(fp);
                        fprintf(stderr, "!ERROR: logger_exit: logger_commit 
failed\n");
                        return LOG_ERR;
                }
 
-               if (fprintf(fp, LLFMT "\n", lg->id) < 0 ||
-                   fclose(fp) < 0) {
-                       fprintf(stderr, "!ERROR: logger_exit: write/flush to %s 
failed\n",
+               if (fprintf(fp, LLFMT "\n", lg->id) < 0) {
+                       (void) fclose(fp);
+                       fprintf(stderr, "!ERROR: logger_exit: write to %s 
failed\n",
+                               filename);
+                       return LOG_ERR;
+               }
+
+               if (fclose(fp) < 0) {
+                       fprintf(stderr, "!ERROR: logger_exit: flush of %s 
failed\n",
                                filename);
                        return LOG_ERR;
                }
diff --git a/sql/backends/monet5/bam/bam_loader.c 
b/sql/backends/monet5/bam/bam_loader.c
--- a/sql/backends/monet5/bam/bam_loader.c
+++ b/sql/backends/monet5/bam/bam_loader.c
@@ -292,14 +292,13 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
        for (i = 0; i < nr_files; ++i) {
                TO_LOG("<bam_loader> Creating alignment tables for file 
'%s'...\n", filenames[i]);
                if ((dbschema == 0
-                        && create_alignment_storage_0(cntxt,
-                                                  "bam.create_storage_0",
-                                                  bws + i) != MAL_SUCCEED)
+                        && (msg = create_alignment_storage_0(cntxt,
+                                                                 
"bam.create_storage_0",
+                                                                 bws + i)) != 
MAL_SUCCEED)
                        || (dbschema == 1
-                       && create_alignment_storage_1(cntxt,
-                                                         
"bam.create_storage_1",
-                                                         bws + i) !=
-                       MAL_SUCCEED)) {
+                               && (msg = create_alignment_storage_1(cntxt,
+                                                                 
"bam.create_storage_1",
+                                                                 bws + i)) != 
MAL_SUCCEED)) {
                        goto cleanup;
                }
        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to