Changeset: d0a7e29dcaf7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d0a7e29dcaf7
Modified Files:
        sql/backends/monet5/sql_subquery.c
Branch: sq2default
Log Message:

Allocation checks and fixed error messages


diffs (truncated from 457 to 300 lines):

diff --git a/sql/backends/monet5/sql_subquery.c 
b/sql/backends/monet5/sql_subquery.c
--- a/sql/backends/monet5/sql_subquery.c
+++ b/sql/backends/monet5/sql_subquery.c
@@ -18,7 +18,7 @@ zero_or_one_error(ptr ret, const bat *bi
        const void *p;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "zero_or_one", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot access 
column descriptor");
        }
        c = BATcount(b);
        if (c == 0) {
@@ -29,22 +29,22 @@ zero_or_one_error(ptr ret, const bat *bi
        } else {
                p = NULL;
                BBPunfix(b->batCacheid);
-               throw(SQL, "zero_or_one", SQLSTATE(21000) "Cardinality 
violation, scalar value expected");
+               throw(SQL, "sql.zero_or_one", SQLSTATE(21000) "Cardinality 
violation, scalar value expected");
        }
        _s = ATOMsize(ATOMtype(b->ttype));
        if (ATOMextern(b->ttype)) {
                _s = ATOMlen(ATOMtype(b->ttype), p);
                *(ptr *) ret = GDKmalloc(_s);
-               if(*(ptr *) ret == NULL){
+               if (*(ptr *) ret == NULL) {
                        BBPunfix(b->batCacheid);
-                       throw(SQL, "zero_or_one", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                       throw(SQL, "sql.zero_or_one", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                }
                memcpy(*(ptr *) ret, p, _s);
        } else if (b->ttype == TYPE_bat) {
                bat bid = *(bat *) p;
                if((*(BAT **) ret = BATdescriptor(bid)) == NULL){
                        BBPunfix(b->batCacheid);
-                       throw(SQL, "zero_or_one", SQLSTATE(HY005) "Cannot 
access column descriptor");
+                       throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot 
access column descriptor");
                }
        } else if (_s == 4) {
                *(int *) ret = *(int *) p;
@@ -104,8 +104,7 @@ SQLsubzero_or_one(bat *ret, const bat *b
                BATmax(h, &max);
                BBPunfix(h->batCacheid);
                if (max != lng_nil && max > 1)
-                       throw(SQL, "assert", SQLSTATE(M0M29) "zero_or_one: 
cardinality violation, scalar expression expected");
-
+                       throw(SQL, "sql.subzero_or_one", SQLSTATE(M0M29) 
"zero_or_one: cardinality violation, scalar expression expected");
        }
        BBPunfix(g->batCacheid);
        if (r == GDK_SUCCEED) {
@@ -123,7 +122,7 @@ SQLall(ptr ret, const bat *bid)
        const void *p;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "all", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        c = BATcount(b);
        if (c == 0) {
@@ -154,16 +153,16 @@ SQLall(ptr ret, const bat *bid)
        if (ATOMextern(b->ttype)) {
                _s = ATOMlen(ATOMtype(b->ttype), p);
                *(ptr *) ret = GDKmalloc(_s);
-               if(*(ptr *) ret == NULL){
+               if (*(ptr *) ret == NULL) {
                        BBPunfix(b->batCacheid);
-                       throw(SQL, "SQLall", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+                       throw(SQL, "sql.all", SQLSTATE(HY001) MAL_MALLOC_FAIL);
                }
                memcpy(*(ptr *) ret, p, _s);
        } else if (b->ttype == TYPE_bat) {
                bat bid = *(bat *) p;
                if ((*(BAT **) ret = BATdescriptor(bid)) == NULL) {
                        BBPunfix(b->batCacheid);
-                       throw(SQL, "all", SQLSTATE(HY005) "Cannot access column 
descriptor");
+                       throw(SQL, "sql.all", SQLSTATE(HY005) "Cannot access 
column descriptor");
                }
        } else if (_s == 4) {
                *(int *) ret = *(int *) p;
@@ -195,16 +194,16 @@ SQLall_grp(bat *ret, const bat *bid, con
 
        (void)no_nil;
        if ((l = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((g = BATdescriptor(*gp)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((e = BATdescriptor(*gpe)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(g->batCacheid);
-               throw(SQL, "all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        li = bat_iterator(l);
        ocmp = ATOMcompare(l->ttype);
@@ -212,7 +211,12 @@ SQLall_grp(bat *ret, const bat *bid, con
                BUN q, o, s, offset = 0;
                BATiter gi = bat_iterator(g);
 
-               pos = GDKmalloc(sizeof(BUN)*BATcount(e)); 
+               if ((pos = GDKmalloc(sizeof(BUN)*BATcount(e))) == NULL) {
+                       BBPunfix(l->batCacheid);
+                       BBPunfix(g->batCacheid);
+                       BBPunfix(e->batCacheid);
+                       throw(SQL, "sql.all =", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+               }
                for (s = 0; s < BATcount(e); s++) 
                        pos[s] = -1;
 
@@ -233,7 +237,15 @@ SQLall_grp(bat *ret, const bat *bid, con
                        }
                }
        }
-       res = COLnew(e->hseqbase, l->ttype, BATcount(e), TRANSIENT);
+
+       if ((res = COLnew(e->hseqbase, l->ttype, BATcount(e), TRANSIENT)) == 
NULL) {
+               BBPunfix(l->batCacheid);
+               BBPunfix(g->batCacheid);
+               BBPunfix(e->batCacheid);
+               GDKfree(pos);
+               throw(SQL, "sql.all =", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
+
        const void *nilp = ATOMnilptr(l->ttype);
        for (p = 0; p < (ssize_t)BATcount(e) && !error; p++) {
                const void *v = nilp;
@@ -248,7 +260,7 @@ SQLall_grp(bat *ret, const bat *bid, con
        }
        GDKfree(pos);
        if (error)
-               throw(SQL, "all =", SQLSTATE(HY005) "all append failed");
+               throw(SQL, "sql.all =", SQLSTATE(HY005) "all append failed");
 
        res->hseqbase = g->hseqbase;
        res->tnil = (has_nil)?1:0;
@@ -268,12 +280,12 @@ SQLnil(bit *ret, const bat *bid)
        BAT *b;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "all", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.nil", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        *ret = FALSE;
        if (BATcount(b) == 0)
                *ret = bit_nil;
-       if (BATcount(b) > 0) {
+       else {
                BUN q, o;
                int (*ocmp) (const void *, const void *);
                BATiter bi = bat_iterator(b);
@@ -303,18 +315,23 @@ SQLnil_grp(bat *ret, const bat *bid, con
 
        (void)no_nil;
        if ((l = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((g = BATdescriptor(*gp)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((e = BATdescriptor(*gpe)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(g->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
-       res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT);
+       if ((res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT)) == 
NULL) {
+               BBPunfix(l->batCacheid);
+               BBPunfix(g->batCacheid);
+               BBPunfix(e->batCacheid);
+               throw(SQL, "sql.any =", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
        BAThseqbase(res, e->hseqbase);
        offset = g->hseqbase - l->hseqbase;
        if (BATcount(g) > 0) {
@@ -386,11 +403,11 @@ SQLanyequal(bit *ret, const bat *bid1, c
        const void *p;
 
        if ((l = BATdescriptor(*bid1)) == NULL) {
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((r = BATdescriptor(*bid2)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        *ret = FALSE;
        if (BATcount(r) > 0) {
@@ -427,24 +444,30 @@ SQLanyequal_grp(bat *ret, const bat *bid
 
        (void)no_nil;
        if ((l = BATdescriptor(*bid1)) == NULL) {
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((r = BATdescriptor(*bid2)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((g = BATdescriptor(*gp)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(r->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((e = BATdescriptor(*gpe)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(r->batCacheid);
                BBPunfix(g->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
-       res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT);
+       if ((res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT)) == 
NULL) {
+               BBPunfix(l->batCacheid);
+               BBPunfix(r->batCacheid);
+               BBPunfix(g->batCacheid);
+               BBPunfix(e->batCacheid);
+               throw(SQL, "sql.any =", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
        BAThseqbase(res, e->hseqbase);
        assert(BATcount(l) == BATcount(r));
        offset = g->hseqbase - l->hseqbase;
@@ -497,31 +520,38 @@ SQLanyequal_grp2(bat *ret, const bat *bi
 
        (void)no_nil;
        if ((l = BATdescriptor(*bid1)) == NULL) {
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((r = BATdescriptor(*bid2)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((rid = BATdescriptor(*Rid)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(r->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((g = BATdescriptor(*gp)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(r->batCacheid);
                BBPunfix(rid->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((e = BATdescriptor(*gpe)) == NULL) {
                BBPunfix(l->batCacheid);
                BBPunfix(r->batCacheid);
                BBPunfix(rid->batCacheid);
                BBPunfix(g->batCacheid);
-               throw(SQL, "any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.any =", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
-       res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT);
+       if ((res = BATconstant(0, TYPE_bit, &F, BATcount(e), TRANSIENT)) == 
NULL) {
+               BBPunfix(l->batCacheid);
+               BBPunfix(r->batCacheid);
+               BBPunfix(rid->batCacheid);
+               BBPunfix(g->batCacheid);
+               BBPunfix(e->batCacheid);
+               throw(SQL, "sql.any =", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
        BAThseqbase(res, e->hseqbase);
        assert(BATcount(l) == BATcount(r));
        offset = g->hseqbase - l->hseqbase;
@@ -576,11 +606,11 @@ SQLallnotequal(bit *ret, const bat *bid1
        const void *p;
 
        if ((l = BATdescriptor(*bid1)) == NULL) {
-               throw(SQL, "all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((r = BATdescriptor(*bid2)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        *ret = TRUE;
        if (BATcount(r) > 0) {
@@ -617,24 +647,30 @@ SQLallnotequal_grp(bat *ret, const bat *
 
        (void)no_nil;
        if ((l = BATdescriptor(*bid1)) == NULL) {
-               throw(SQL, "all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
+               throw(SQL, "sql.all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
        }
        if ((r = BATdescriptor(*bid2)) == NULL) {
                BBPunfix(l->batCacheid);
-               throw(SQL, "all <>", SQLSTATE(HY005) "Cannot access column 
descriptor");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to