Changeset: cfe63ced5b16 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cfe63ced5b16
Modified Files:
        sql/backends/monet5/sql_execute.c
        sql/common/sql_list.c
        sql/server/sql_atom.c
        sql/server/sql_mvc.c
        sql/server/sql_parser.y
        sql/server/sql_semantic.c
        sql/server/sql_semantic.h
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: default
Log Message:

More defensive lines


diffs (truncated from 411 to 300 lines):

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
@@ -922,7 +922,7 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                d = strtol(p, &p, 10);
                p++; /* skip , */
                s = strtol(p, &p, 10);
-               
+
                sql_find_subtype(&t, tnme, d, s);
                a = atom_general(m->sa, &t, NULL);
                /* the argument list may have holes and maybe out of order, ie
@@ -931,7 +931,8 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                 * */
                if (nr >= 0) { 
                        append(ops, exp_atom_ref(m->sa, nr, &t));
-                       sql_set_arg(m, nr, a);
+                       if(!sql_set_arg(m, nr, a))
+                               return 
createException(SQL,"RAstatement2",SQLSTATE(HY001) MAL_MALLOC_FAIL);
                } else {
                        if(!stack_push_var(m, vnme+1, &t))
                                return 
createException(SQL,"RAstatement2",SQLSTATE(HY001) MAL_MALLOC_FAIL);
diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c
--- a/sql/common/sql_list.c
+++ b/sql/common/sql_list.c
@@ -467,9 +467,11 @@ list_select(list *l, void *key, fcmp cmp
 
        if (key && l) {
                res = list_new_(l);
-               for (n = l->h; n; n = n->next) 
-                       if (cmp(n->data, key) == 0) 
-                               list_append(res, dup?dup(n->data):n->data);
+               if(res) {
+                       for (n = l->h; n; n = n->next)
+                               if (cmp(n->data, key) == 0)
+                                       list_append(res, 
dup?dup(n->data):n->data);
+               }
        }
        return res;
 }
@@ -482,16 +484,18 @@ list_order(list *l, fcmp cmp, fdup dup)
        node *m, *n = NULL;
 
        /* use simple insert sort */
-       for (n = l->h; n; n = n->next) {
-               int append = 1;
-               for (m = res->h; m && append; m = m->next) {
-                       if (cmp(n->data, m->data) > 0) {
-                               list_append_before(res, m, 
dup?dup(n->data):n->data);
-                               append = 0;
+       if(res) {
+               for (n = l->h; n; n = n->next) {
+                       int append = 1;
+                       for (m = res->h; m && append; m = m->next) {
+                               if (cmp(n->data, m->data) > 0) {
+                                       list_append_before(res, m, dup ? 
dup(n->data) : n->data);
+                                       append = 0;
+                               }
                        }
+                       if (append)
+                               list_append(res, dup ? dup(n->data) : n->data);
                }
-               if (append)
-                       list_append(res, dup?dup(n->data):n->data);
        }
        return res;
 }
@@ -502,9 +506,11 @@ list_distinct(list *l, fcmp cmp, fdup du
        list *res = list_new_(l);
        node *n = NULL;
 
-       for (n = l->h; n; n = n->next) {
-               if (!list_find(res, n->data, cmp)) {
-                       list_append(res, dup?dup(n->data):n->data);
+       if(res) {
+               for (n = l->h; n; n = n->next) {
+                       if (!list_find(res, n->data, cmp)) {
+                               list_append(res, dup ? dup(n->data) : n->data);
+                       }
                }
        }
        return res;
@@ -571,12 +577,14 @@ list_map(list *l, void *data, fmap map)
 
        node *n = l->h;
 
-       while (n) {
-               void *v = map(n->data, data);
+       if(res) {
+               while (n) {
+                       void *v = map(n->data, data);
 
-               if (v)
-                       list_append(res, v);
-               n = n->next;
+                       if (v)
+                               list_append(res, v);
+                       n = n->next;
+               }
        }
        return res;
 }
@@ -622,7 +630,7 @@ list *
 list_dup(list *l, fdup dup)
 {
        list *res = list_new_(l);
-       return list_merge(res, l, dup);
+       return res ? list_merge(res, l, dup) : NULL;
 }
 
 
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -500,14 +500,14 @@ atom2sql(atom *a)
        case EC_TIMESTAMP:
                if (a->data.vtype == TYPE_str) {
                        if (a->data.val.sval)
-                               sprintf(buf, "%s '%s'", a->tpe.type->sqlname, 
+                               sprintf(buf, "%s '%s'", a->tpe.type->sqlname,
                                        a->data.val.sval);
                        else
                                sprintf(buf, "NULL");
                }
                break;
-        default:
-                snprintf(buf, BUFSIZ, "atom2sql(TYPE_%d) not implemented", 
a->data.vtype);
+       default:
+               snprintf(buf, BUFSIZ, "atom2sql(TYPE_%d) not implemented", 
a->data.vtype);
        }
        return _STRDUP(buf);
 }
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -598,7 +598,7 @@ mvc_create(int clientid, backend_stack s
 int
 mvc_reset(mvc *m, bstream *rs, stream *ws, int debug, int globalvars)
 {
-       int i;
+       int i, res = 1;
        sql_trans *tr;
 
        if (mvc_debug)
@@ -611,13 +611,15 @@ mvc_reset(mvc *m, bstream *rs, stream *w
                        tr = sql_trans_destroy(tr);
                store_unlock();
        }
-       if (tr)
-               sql_session_reset(m->session, 1 /*autocommit on*/);
+       if (tr && !sql_session_reset(m->session, 1 /*autocommit on*/))
+               res = 0;
 
        if (m->sa)
                m->sa = sa_reset(m->sa);
-       else 
+       else
                m->sa = sa_create();
+       if(!m->sa)
+               res = 0;
 
        m->errstr[0] = '\0';
 
@@ -660,7 +662,7 @@ mvc_reset(mvc *m, bstream *rs, stream *w
        m->results = NULL;
 
        scanner_init(&m->scanner, rs, ws);
-       return m->sa ? 0 : -1;
+       return res;
 }
 
 void
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -2882,7 +2882,12 @@ null:
                /* replace by argument */
                atom *a = atom_general(SA, sql_bind_localtype("void"), NULL);
 
-               sql_add_arg( m, a);
+               if(!sql_add_arg( m, a)) {
+                       char *msg = sql_message(SQLSTATE(HY001) "allocation 
failure");
+                       yyerror(m, msg);
+                       _DELETE(msg);
+                       YYABORT;
+               }
                $$ = _symbol_create_list( SQL_COLUMN,
                        append_int(L(), m->argc-1));
           } else {
@@ -4157,22 +4162,27 @@ opt_alias_name:
 atom:
     literal
        { 
-         if (m->emode == m_normal && m->caching) { 
-               /* replace by argument */
-               AtomNode *an = (AtomNode*)$1;
-       
-               sql_add_arg( m, an->a);
+         if (m->emode == m_normal && m->caching) {
+               /* replace by argument */
+               AtomNode *an = (AtomNode*)$1;
+
+               if(!sql_add_arg( m, an->a)) {
+                       char *msg = sql_message(SQLSTATE(HY001) "allocation 
failure");
+                       yyerror(m, msg);
+                       _DELETE(msg);
+                       YYABORT;
+               }
                an->a = NULL;
-               /* we miss use SQL_COLUMN also for param's, maybe
-                       change SQL_COLUMN to SQL_IDENT */
-               $$ = _symbol_create_list( SQL_COLUMN,
+               /* we miss use SQL_COLUMN also for param's, maybe
+                               change SQL_COLUMN to SQL_IDENT */
+               $$ = _symbol_create_list( SQL_COLUMN,
                        append_int(L(), m->argc-1));
-          } else {
-               AtomNode *an = (AtomNode*)$1;
+         } else {
+               AtomNode *an = (AtomNode*)$1;
                atom *a = an->a; 
                an->a = atom_dup(SA, a); 
                $$ = $1;
-          }
+         }
        }
  ;
 
@@ -5133,7 +5143,7 @@ data_type:
                _DELETE(msg);
                YYABORT;
        } else if (geoSubType == -1) {
-               char *msg = sql_message("allocation failure");
+               char *msg = sql_message(SQLSTATE(HY001) "allocation failure");
                $$.type = NULL;
                yyerror(m, msg);
                _DELETE(msg);
@@ -5159,7 +5169,7 @@ subgeometry_type:
                _DELETE(msg);
                YYABORT;
        } else if(subtype == -1) {
-               char *msg = sql_message("allocation failure");
+               char *msg = sql_message(SQLSTATE(HY001) "allocation failure");
                yyerror(m, msg);
                _DELETE(msg);
                YYABORT;
@@ -5176,7 +5186,7 @@ subgeometry_type:
                _DELETE(msg);
                YYABORT;
        } else if (subtype == -1) {
-               char *msg = sql_message("allocation failure");
+               char *msg = sql_message(SQLSTATE(HY001) "allocation failure");
                yyerror(m, msg);
                _DELETE(msg);
                YYABORT;
diff --git a/sql/server/sql_semantic.c b/sql/server/sql_semantic.c
--- a/sql/server/sql_semantic.c
+++ b/sql/server/sql_semantic.c
@@ -33,28 +33,44 @@
  * !SQL  <informative message, reserved for ...rows affected>
  */
 
-void
+atom *
 sql_add_arg(mvc *sql, atom *v)
 {
-       if (sql->argc == sql->argmax) {
-               sql->argmax *= 2;
-               sql->args = RENEW_ARRAY(atom*,sql->args,sql->argmax);
+       atom** new_args;
+       int next_size = sql->argmax;
+       if (sql->argc == next_size) {
+               next_size *= 2;
+               new_args = RENEW_ARRAY(atom*,sql->args,next_size);
+               if(new_args) {
+                       sql->args = new_args;
+                       sql->argmax = next_size;
+               } else
+                       return NULL;
        }
        sql->args[sql->argc++] = v;
+       return v;
 }
 
-void
+atom *
 sql_set_arg(mvc *sql, int nr, atom *v)
 {
-       if (nr >= sql->argmax) {
-               sql->argmax *= 2;
-               if (nr >= sql->argmax)
-                       sql->argmax = nr*2;
-               sql->args = RENEW_ARRAY(atom*,sql->args,sql->argmax);
+       atom** new_args;
+       int next_size = sql->argmax;
+       if (nr >= next_size) {
+               next_size *= 2;
+               if (nr >= next_size)
+                       next_size = nr*2;
+               new_args = RENEW_ARRAY(atom*,sql->args,next_size);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to