Changeset: bb36451050ad for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bb36451050ad
Modified Files:
        gdk/ChangeLog
        gdk/gdk_batop.c
        gdk/gdk_value.c
        monetdb5/mal/mal_builder.c
        monetdb5/mal/mal_factory.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/scheduler/run_memo.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_execute.c
Branch: default
Log Message:

After VALinit, now VALcopy also returns NULL if malloc fails.


diffs (227 lines):

diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -1,6 +1,10 @@
 # ChangeLog file for MonetDB
 # This file is updated with Maddlog
 
+* Wed Sep 14 2016 Sjoerd Mullender <[email protected]>
+- VALcopy and VALinit both return their first argument on success or
+  (and that's new) NULL on (allocation) failure.
+
 * Tue Jul 26 2016 Sjoerd Mullender <[email protected]>
 - BATattach now can also create a str BAT from a file consisting of
   null-terminated strings.  The input file must be encoded using UTF-8.
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1347,7 +1347,8 @@ BATsetprop(BAT *b, int idx, int type, vo
        ValRecord vr;
        PROPrec *p = BATgetprop(b, idx);
 
-       if (!p && (p = (PROPrec *) GDKmalloc(sizeof(PROPrec))) != NULL) {
+       if (p == NULL &&
+           (p = (PROPrec *) GDKmalloc(sizeof(PROPrec))) != NULL) {
                p->id = idx;
                p->next = b->tprops;
                p->v.vtype = 0;
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -134,7 +134,9 @@ VALempty(ValPtr v)
 
 /* Create a copy of S into D, allocating space for external values
  * (non-fixed sized values).  See VALinit for a version where the
- * source is not in a VALRecord. */
+ * source is not in a VALRecord.
+ *
+ * Returns NULL In case of (malloc) failure. */
 ValPtr
 VALcopy(ValPtr d, const ValRecord *s)
 {
@@ -146,6 +148,8 @@ VALcopy(ValPtr d, const ValRecord *s)
        } else if (s->vtype == TYPE_str) {
                d->vtype = TYPE_str;
                d->val.sval = GDKstrdup(s->val.sval);
+               if (d->val.sval == NULL)
+                       return NULL;
                d->len = strLen(d->val.sval);
        } else if (s->vtype == TYPE_bit) {
                d->vtype = s->vtype;
@@ -157,8 +161,9 @@ VALcopy(ValPtr d, const ValRecord *s)
                d->vtype = s->vtype;
                d->len = ATOMlen(d->vtype, p);
                d->val.pval = GDKmalloc(d->len);
-               if (d->val.pval)
-                       memcpy(d->val.pval, p, d->len);
+               if (d->val.pval == NULL)
+                       return NULL;
+               memcpy(d->val.pval, p, d->len);
        }
        return d;
 }
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
@@ -621,7 +621,10 @@ pushValue(MalBlkPtr mb, InstrPtr q, ValP
 
        if (q == NULL)
                return NULL;
-       VALcopy(&cst, vr);
+       if (VALcopy(&cst, vr) == NULL) {
+               freeInstruction(q);
+               return NULL;
+       }
        _t = defConstant(mb,cst.vtype,&cst);
        return pushArgument(mb, q, _t);
 }
diff --git a/monetdb5/mal/mal_factory.c b/monetdb5/mal/mal_factory.c
--- a/monetdb5/mal/mal_factory.c
+++ b/monetdb5/mal/mal_factory.c
@@ -106,7 +106,7 @@ runFactory(Client cntxt, MalBlkPtr mb, M
        /* inherit debugging */
        cmd = stk->cmd;
        if ( pl->stk == NULL)
-                       throw(MAL, "factory.new", "internal error, stack frame 
missing");
+               throw(MAL, "factory.new", "internal error, stack frame 
missing");
 
        /* copy the calling arguments onto the stack
           of the factory */
@@ -118,7 +118,8 @@ runFactory(Client cntxt, MalBlkPtr mb, M
                        k--;
 
                rhs = &pl->env->stk[getArg(pci, i)];
-               VALcopy(lhs, rhs);
+               if (VALcopy(lhs, rhs) == NULL)
+                       throw(MAL, "factory.call", MAL_MALLOC_FAIL);
                if( lhs->vtype == TYPE_bat )
                        BBPincref(lhs->val.bval, TRUE);
        }
@@ -131,7 +132,8 @@ runFactory(Client cntxt, MalBlkPtr mb, M
                        if( isVarConstant(mb,i) > 0 ){
                                if( !isVarDisabled(mb,i)){
                                        rhs = &getVarConstant(mb,i);
-                                       VALcopy(lhs,rhs);
+                                       if (VALcopy(lhs,rhs) == NULL)
+                                               throw(MAL, "factory.call", 
MAL_MALLOC_FAIL);
                                }
                        } else{
                                lhs->vtype = getVarGDKType(mb,i);
@@ -187,7 +189,8 @@ callFactory(Client cntxt, MalBlkPtr mb, 
                if( isVarConstant(mb,i) > 0 ){
                        lhs = &stk->stk[i];
                        rhs = &getVarConstant(mb,i);
-                       VALcopy(lhs,rhs);
+                       if (VALcopy(lhs,rhs) == NULL)
+                               throw(MAL, "factory.call", MAL_MALLOC_FAIL);
                } else {
                        lhs = &stk->stk[i];
                        lhs->vtype = getVarGDKType(mb,i);
@@ -209,7 +212,8 @@ callFactory(Client cntxt, MalBlkPtr mb, 
        i = psig->retc;
        for (i = psig->retc; i < psig->argc; i++) {
                lhs = &pl->stk->stk[psig->argv[i]];
-               VALcopy(lhs, argv[i]);
+               if (VALcopy(lhs, argv[i]) == NULL)
+                       throw(MAL, "factory.call", MAL_MALLOC_FAIL);
                if( lhs->vtype == TYPE_bat )
                        BBPincref(lhs->val.bval, TRUE);
        }
@@ -277,7 +281,8 @@ yieldResult(MalBlkPtr mb, InstrPtr p, in
 #endif
                                rhs = &pl->stk->stk[getArg(p, i)];
                                lhs = &pl->env->stk[getArg(pl->pci, i)];
-                               VALcopy(lhs, rhs);
+                               if (VALcopy(lhs, rhs) == NULL)
+                                       return -1;
                        }
                        return (int) (pl-plants);
                }
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -857,7 +857,10 @@ copyVariable(MalBlkPtr dst, VarPtr v)
        w->type = v->type;
        w->flags = v->flags;
        w->rowcnt = v->rowcnt;
-       VALcopy(&w->value, &v->value);
+       if (VALcopy(&w->value, &v->value) == NULL) {
+               GDKfree(w);
+               return -1;
+       }
        dst->var[dst->vtop] = w;
        return 0;
 }
@@ -1137,7 +1140,8 @@ convertConstant(int type, ValPtr vr)
                ptr d = NULL;
 
                if (isaBatType(type)) {
-                       VALinit(vr, TYPE_bat, ATOMnilptr(TYPE_bat));
+                       if (VALinit(vr, TYPE_bat, ATOMnilptr(TYPE_bat)) == NULL)
+                               throw(MAL, "convertConstant", MAL_MALLOC_FAIL);
                        break;
                }
                /* see if an atomFromStr() function is available */
@@ -1215,7 +1219,8 @@ cpyConstant(MalBlkPtr mb, VarPtr vr)
        int i;
        ValRecord cst;
 
-       VALcopy(&cst, &vr->value);
+       if (VALcopy(&cst, &vr->value) == NULL)
+               return -1;
 
        i = defConstant(mb, vr->type, &cst);
        return i;
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
@@ -426,7 +426,8 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
                assert(stk);
                for (i = pci->retc; i < pci->argc; i++) {
                        lhs = &stk->stk[pci->argv[i]];
-                       VALcopy(lhs, argv[i]);
+                       if (VALcopy(lhs, argv[i]) == NULL)
+                               throw(MAL, "mal.interpreter", MAL_MALLOC_FAIL);
                        if (lhs->vtype == TYPE_bat)
                                BBPincref(lhs->val.bval, TRUE);
                }
diff --git a/monetdb5/scheduler/run_memo.c b/monetdb5/scheduler/run_memo.c
--- a/monetdb5/scheduler/run_memo.c
+++ b/monetdb5/scheduler/run_memo.c
@@ -212,8 +212,8 @@ RUNpickResult(Client cntxt, MalBlkPtr mb
                        rhs = &stk->stk[getArg(p, i)];
                        if ((rhs)->vtype < TYPE_str)
                                *lhs = *rhs;
-                       else
-                               VALcopy(lhs, rhs);
+                       else if (VALcopy(lhs, rhs) == NULL)
+                               throw(MAL, "scheduler.pick", MAL_MALLOC_FAIL);
                        if (lhs->vtype == TYPE_bat)
                                BBPincref(lhs->val.bval, TRUE);
                        return MAL_SUCCEED;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -1657,7 +1657,8 @@ getVariable(Client cntxt, MalBlkPtr mb, 
        }
        src = &a->data;
        dst = &stk->stk[getArg(pci, 0)];
-       VALcopy(dst, src);
+       if (VALcopy(dst, src) == NULL)
+               throw(MAL, "sql.getVariable", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -300,7 +300,8 @@ SQLrun(Client c, backend *be, mvc *m){
                                        throw(SQL, "sql.prepare", "07001!EXEC: 
wrong type for argument %d of " "query template : %s, expected %s", i + 1, 
atom_type(arg)->type->sqlname, pt->type->sqlname);
                                }
                                val= (ValPtr) &arg->data;
-                               VALcopy(&mb->var[j+retc]->value, val);
+                               if (VALcopy(&mb->var[j+retc]->value, val) == 
NULL)
+                                       throw(MAL, "sql.prepare", 
MAL_MALLOC_FAIL);
                                setVarConstant(mb, j+retc);
                                setVarFixed(mb, j+retc);
                        }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to