Changeset: ff9f428dbd01 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ff9f428dbd01
Modified Files:
        monetdb5/mal/mal_builder.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_namespace.c
        sql/backends/monet5/sql_gencode.c
        sql/common/sql_string.c
Branch: Jan2014
Log Message:

Added some error checking.


diffs (truncated from 746 to 300 lines):

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
@@ -33,8 +33,17 @@ newAssignment(MalBlkPtr mb)
 {
        InstrPtr q = newInstruction(mb,ASSIGNsymbol);
 
-       getArg(q,0)= newTmpVariable(mb,TYPE_any);
+       if (q == NULL)
+               return NULL;
+       if ((getArg(q,0)= newTmpVariable(mb,TYPE_any)) < 0) {
+               freeInstruction(q);
+               return NULL;
+       }
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        return q;
 }
 
@@ -43,10 +52,20 @@ newStmt(MalBlkPtr mb, char *module, char
 {
        InstrPtr q = newInstruction(mb,ASSIGNsymbol);
 
-       setModuleId(q, (module) ? putName(module, strlen(module)) : NULL);
-       setFunctionId(q, (name) ? putName(name, strlen(name)) : NULL);
+       if (q == NULL)
+               return NULL;
+       setModuleId(q, putName(module, strlen(module)));
+       setFunctionId(q, putName(name, strlen(name)));
        setDestVar(q, newTmpVariable(mb, TYPE_any));
+       if (getDestVar(q) < 0) {
+               freeInstruction(q);
+               return NULL;
+       }
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        return q;
 }
 
@@ -55,10 +74,20 @@ newStmt1(MalBlkPtr mb, str module, char 
 {
        InstrPtr q = newInstruction(mb,ASSIGNsymbol);
 
-       setModuleId(q, module);
-       setFunctionId(q, (name) ? putName(name, strlen(name)) : NULL);
+       if (q == NULL)
+               return NULL;
+       setModuleId(q, putName(module, strlen(module)));
+       setFunctionId(q, putName(name, strlen(name)));
        setDestVar(q, newTmpVariable(mb, TYPE_any));
+       if (getDestVar(q) < 0) {
+               freeInstruction(q);
+               return NULL;
+       }
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        return q;
 }
 
@@ -67,10 +96,20 @@ newStmt2(MalBlkPtr mb, str module, char 
 {
        InstrPtr q = newInstruction(mb,ASSIGNsymbol);
 
-       setModuleId(q, module);
-       setFunctionId(q, name);
+       if (q == NULL)
+               return NULL;
+       setModuleId(q, putName(module, strlen(module)));
+       setFunctionId(q, putName(name, strlen(name)));
        setDestVar(q, newTmpVariable(mb, TYPE_any));
+       if (getDestVar(q) < 0) {
+               freeInstruction(q);
+               return NULL;
+       }
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        return q;
 }
 
@@ -79,8 +118,17 @@ newReturnStmt(MalBlkPtr mb)
 {
        InstrPtr q = newInstruction(mb,ASSIGNsymbol);
 
-       getArg(q,0)= newTmpVariable(mb,TYPE_any);
+       if (q == NULL)
+               return NULL;
+       if ((getArg(q,0)= newTmpVariable(mb,TYPE_any)) < 0) {
+               freeInstruction(q);
+               return NULL;
+       }
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        q->barrier= RETURNsymbol;
        return q;
 }
@@ -90,6 +138,8 @@ newFcnCall(MalBlkPtr mb, char *mod, char
 {
        InstrPtr q = newAssignment(mb);
 
+       if (q == NULL)
+               return NULL;
        setModuleId(q, putName(mod, strlen(mod)));
        setFunctionId(q, putName(fcn, strlen(fcn)));
        return q;
@@ -101,13 +151,22 @@ newComment(MalBlkPtr mb, const char *val
        InstrPtr q = newInstruction(NULL,REMsymbol);
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_str;
-       cst.val.sval= GDKstrdup(val);
+       if ((cst.val.sval= GDKstrdup(val)) == NULL) {
+               freeInstruction(q);
+               return NULL;
+       }
        cst.len= (int) strlen(cst.val.sval);
        getArg(q,0) = defConstant(mb,TYPE_str,&cst);
        clrVarConstant(mb,getArg(q,0));
        setVarDisabled(mb,getArg(q,0));
        pushInstruction(mb, q);
+       if (mb->errors) {
+               freeInstruction(q);
+               return NULL;
+       }
        return q;
 }
 
@@ -117,9 +176,14 @@ newCatchStmt(MalBlkPtr mb, str nme)
        InstrPtr q = newAssignment(mb);
        int i= findVariable(mb,nme);
 
+       if (q == NULL)
+               return NULL;
        q->barrier = CATCHsymbol;
        if ( i< 0) {
-               getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str);
+               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+                       freeInstruction(q);
+                       return NULL;
+               }
                setVarUDFtype(mb,getArg(q,0));
        } else getArg(q,0) = i;
        return q;
@@ -130,10 +194,16 @@ newRaiseStmt(MalBlkPtr mb, str nme)
        InstrPtr q = newAssignment(mb);
        int i= findVariable(mb,nme);
 
+       if (q == NULL)
+               return NULL;
        q->barrier = RAISEsymbol;
-       if ( i< 0)
-               getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str);
-       else getArg(q,0) = i;
+       if ( i< 0) {
+               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+                       freeInstruction(q);
+                       return NULL;
+               }
+       } else
+               getArg(q,0) = i;
        return q;
 }
 
@@ -143,10 +213,16 @@ newExitStmt(MalBlkPtr mb, str nme)
        InstrPtr q = newAssignment(mb);
        int i= findVariable(mb,nme);
 
+       if (q == NULL)
+               return NULL;
        q->barrier = EXITsymbol;
-       if ( i< 0)
-               getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str);
-       else getArg(q,0) = i;
+       if ( i< 0) {
+               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+                       freeInstruction(q);
+                       return NULL;
+               }
+       } else
+               getArg(q,0) = i;
        return q;
 }
 
@@ -156,6 +232,8 @@ pushInt(MalBlkPtr mb, InstrPtr q, int va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_int;
        cst.val.ival= val;
        cst.len = 0;
@@ -169,6 +247,8 @@ pushWrd(MalBlkPtr mb, InstrPtr q, wrd va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_wrd;
        cst.val.wval= val;
        cst.len = 0;
@@ -182,6 +262,8 @@ pushBte(MalBlkPtr mb, InstrPtr q, bte va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_bte;
        cst.val.btval= val;
        cst.len = 0;
@@ -195,6 +277,8 @@ pushOid(MalBlkPtr mb, InstrPtr q, oid va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_oid;
        cst.val.oval= val;
        cst.len = 0;
@@ -208,6 +292,8 @@ pushVoid(MalBlkPtr mb, InstrPtr q)
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_void;
        cst.val.oval= oid_nil;
        cst.len = 0;
@@ -221,6 +307,8 @@ pushLng(MalBlkPtr mb, InstrPtr q, lng va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_lng;
        cst.val.lval= val;
        cst.len = 0;
@@ -234,6 +322,8 @@ pushDbl(MalBlkPtr mb, InstrPtr q, dbl va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_dbl;
        cst.val.dval= val;
        cst.len = 0;
@@ -247,6 +337,8 @@ pushFlt(MalBlkPtr mb, InstrPtr q, flt va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_flt;
        cst.val.fval= val;
        cst.len = 0;
@@ -260,8 +352,13 @@ pushStr(MalBlkPtr mb, InstrPtr q, const 
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_str;
-       cst.val.sval= GDKstrdup(Val);
+       if ((cst.val.sval= GDKstrdup(Val)) == NULL) {
+               freeInstruction(q);
+               return NULL;
+       }
        cst.len= (int) strlen(cst.val.sval);
        _t = defConstant(mb,TYPE_str,&cst);
        return pushArgument(mb, q, _t);
@@ -273,6 +370,8 @@ pushBit(MalBlkPtr mb, InstrPtr q, bit va
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
+               return NULL;
        cst.vtype= TYPE_bit;
        cst.val.btval= val;
        cst.len = 0;
@@ -287,6 +386,8 @@ pushNil(MalBlkPtr mb, InstrPtr q, int tp
        int _t;
        ValRecord cst;
 
+       if (q == NULL)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to