Changeset: 054332dbcbbb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/054332dbcbbb
Modified Files:
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_calc.c
        gdk/gdk_storage.c
Branch: Jul2021
Log Message:

More check then dereference


diffs (truncated from 305 to 300 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2140,12 +2140,12 @@ HEAPcommitpersistence(Heap *hp, bool wri
 gdk_return
 BATcheckmodes(BAT *b, bool existing)
 {
-       bool wr = (b->batRestricted == BAT_WRITE);
        storage_t m1 = STORE_MEM, m3 = STORE_MEM;
-       bool dirty = false;
+       bool dirty = false, wr;
 
        BATcheck(b, GDK_FAIL);
 
+       wr = (b->batRestricted == BAT_WRITE);
        if (b->ttype) {
                m1 = HEAPcommitpersistence(b->theap, wr, existing);
                dirty |= (b->theap->newstorage != m1);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -2961,9 +2961,11 @@ BATcount_no_nil(BAT *b, BAT *s)
        int t;
        int (*cmp)(const void *, const void *);
        struct canditer ci;
-       oid hseq = b->hseqbase;
+       oid hseq;
 
        BATcheck(b, 0);
+
+       hseq = b->hseqbase;
        n = canditer_init(&ci, b, s);
        if (b->tnonil)
                return n;
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -356,12 +356,14 @@ BATcalcnot(BAT *b, BAT *s)
        BAT *bn;
        BUN nils = 0;
        BUN i, ncand;
-       oid x, bhseqbase = b->hseqbase;
+       oid x, bhseqbase;
        struct canditer ci;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
        if (ncand == 0)
                return BATconstant(ci.hseq, b->ttype,
@@ -533,12 +535,14 @@ BATcalcnegate(BAT *b, BAT *s)
        BAT *bn;
        BUN nils = 0;
        BUN i, ncand;
-       oid x, bhseqbase = b->hseqbase;
+       oid x, bhseqbase;
        struct canditer ci;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
        if (ncand == 0)
                return BATconstant(ci.hseq, b->ttype,
@@ -662,14 +666,16 @@ BATcalcabsolute(BAT *b, BAT *s)
 {
        lng t0 = 0;
        BAT *bn;
-       BUN nils= 0;
+       BUN nils = 0;
        BUN i, ncand;
-       oid x, bhseqbase = b->hseqbase;
+       oid x, bhseqbase;
        struct canditer ci;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
        if (ncand == 0)
                return BATconstant(ci.hseq, b->ttype,
@@ -799,12 +805,14 @@ BATcalciszero(BAT *b, BAT *s)
        BAT *bn;
        BUN nils = 0;
        BUN i, ncand;
-       oid x, bhseqbase = b->hseqbase;
+       oid x, bhseqbase;
        struct canditer ci;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
        if (ncand == 0)
                return BATconstant(ci.hseq, TYPE_bit,
@@ -932,12 +940,14 @@ BATcalcsign(BAT *b, BAT *s)
        BAT *bn;
        BUN nils = 0;
        BUN i, ncand;
-       oid x, bhseqbase = b->hseqbase;
+       oid x, bhseqbase;
        struct canditer ci;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
        if (ncand == 0)
                return BATconstant(ci.hseq, TYPE_bte,
@@ -1078,12 +1088,13 @@ BATcalcisnil_implementation(BAT *b, BAT 
        struct canditer ci;
        bit *restrict dst;
        BUN nils = 0;
-       oid bhseqbase = b->hseqbase;
+       oid bhseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
 
+       bhseqbase = b->hseqbase;
        ncand = canditer_init(&ci, b, s);
 
        if (b->tnonil || BATtdense(b)) {
@@ -1234,13 +1245,15 @@ BATcalcmin(BAT *b1, BAT *b2, BAT *s1, BA
        bool nils = false;
        BUN ncand;
        struct canditer ci1, ci2;
-       oid b1hseqbase = b1->hseqbase, b2hseqbase = b2->hseqbase;
+       oid b1hseqbase, b2hseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b1, NULL);
        BATcheck(b2, NULL);
 
+       b1hseqbase = b1->hseqbase;
+       b2hseqbase = b2->hseqbase;
        if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -1436,13 +1449,15 @@ BATcalcmin_no_nil(BAT *b1, BAT *b2, BAT 
        bool nils = false;
        BUN ncand;
        struct canditer ci1, ci2;
-       oid b1hseqbase = b1->hseqbase, b2hseqbase = b2->hseqbase;
+       oid b1hseqbase, b2hseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b1, NULL);
        BATcheck(b2, NULL);
 
+       b1hseqbase = b1->hseqbase;
+       b2hseqbase = b2->hseqbase;
        if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -1632,13 +1647,17 @@ BATcalcmincst(BAT *b, const ValRecord *v
        BUN ncand;
        struct canditer ci;
        const void *p2;
-       const void *restrict nil = ATOMnilptr(b->ttype);
-       int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype);
-       oid bhseqbase = b->hseqbase;
+       const void *restrict nil;
+       int (*cmp)(const void *, const void *);
+       oid bhseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       nil = ATOMnilptr(b->ttype);
+       cmp = ATOMcompare(b->ttype);
+       bhseqbase = b->hseqbase;
        if (ATOMtype(b->ttype) != v->vtype) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -1779,13 +1798,17 @@ BATcalcmincst_no_nil(BAT *b, const ValRe
        BUN ncand;
        struct canditer ci;
        const void *p2;
-       const void *restrict nil = ATOMnilptr(b->ttype);
-       int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype);
-       oid bhseqbase = b->hseqbase;
+       const void *restrict nil;
+       int (*cmp)(const void *, const void *);
+       oid bhseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       nil = ATOMnilptr(b->ttype);
+       cmp = ATOMcompare(b->ttype);
+       bhseqbase = b->hseqbase;
        if (ATOMtype(b->ttype) != v->vtype) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -1916,13 +1939,15 @@ BATcalcmax(BAT *b1, BAT *b2, BAT *s1, BA
        bool nils = false;
        BUN ncand;
        struct canditer ci1, ci2;
-       oid b1hseqbase = b1->hseqbase, b2hseqbase = b2->hseqbase;
+       oid b1hseqbase, b2hseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b1, NULL);
        BATcheck(b2, NULL);
 
+       b1hseqbase = b1->hseqbase;
+       b2hseqbase = b2->hseqbase;
        if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -2080,13 +2105,15 @@ BATcalcmax_no_nil(BAT *b1, BAT *b2, BAT 
        bool nils = false;
        BUN ncand;
        struct canditer ci1, ci2;
-       oid b1hseqbase = b1->hseqbase, b2hseqbase = b2->hseqbase;
+       oid b1hseqbase, b2hseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b1, NULL);
        BATcheck(b2, NULL);
 
+       b1hseqbase = b1->hseqbase;
+       b2hseqbase = b2->hseqbase;
        if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -2265,13 +2292,17 @@ BATcalcmaxcst(BAT *b, const ValRecord *v
        BUN ncand;
        struct canditer ci;
        const void *p2;
-       const void *restrict nil = ATOMnilptr(b->ttype);
-       int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype);
-       oid bhseqbase = b->hseqbase;
+       const void *restrict nil;
+       int (*cmp)(const void *, const void *);
+       oid bhseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       nil = ATOMnilptr(b->ttype);
+       cmp = ATOMcompare(b->ttype);
+       bhseqbase = b->hseqbase;
        if (ATOMtype(b->ttype) != v->vtype) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
@@ -2389,13 +2420,17 @@ BATcalcmaxcst_no_nil(BAT *b, const ValRe
        BUN ncand;
        struct canditer ci;
        const void *p2;
-       const void *restrict nil = ATOMnilptr(b->ttype);
-       int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype);
-       oid bhseqbase = b->hseqbase;
+       const void *restrict nil;
+       int (*cmp)(const void *, const void *);
+       oid bhseqbase;
 
        TRC_DEBUG_IF(ALGO) t0 = GDKusec();
 
        BATcheck(b, NULL);
+
+       nil = ATOMnilptr(b->ttype);
+       cmp = ATOMcompare(b->ttype);
+       bhseqbase = b->hseqbase;
        if (ATOMtype(b->ttype) != v->vtype) {
                GDKerror("inputs have incompatible types\n");
                return NULL;
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -782,11 +782,12 @@ BATsave_locked(BAT *b, BATiter *bi)
 {
        gdk_return err = GDK_SUCCEED;
        const char *nme;
-       bool dosync = (BBP_status(b->batCacheid) & BBPPERSISTENT) != 0;
+       bool dosync;
 
-       assert(!GDKinmemory(b->theap->farmid));
        BATcheck(b, GDK_FAIL);
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to