shithub: mc

Download patch

ref: fa8e0920764f9f298d6b6ac9471c862aec024e01
parent: c1d212afb2854639aae86b9a44650f0769d0b90c
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jun 26 13:51:32 EDT 2015

Fix a few misc memory bugs.

--- a/6/locs.c
+++ b/6/locs.c
@@ -67,7 +67,7 @@
     assert(e->type == Nexpr);
     lbl = e->expr.args[0];
     assert(lbl->type == Nlit);
-    assert(lbl->lit.littype = Llbl);
+    assert(lbl->lit.littype == Llbl);
     return locstrlbl(lbl->lit.lblval);
 }
 
--- a/6/ra.c
+++ b/6/ra.c
@@ -297,8 +297,8 @@
             bsunion(bb[i]->livein, bb[i]->use);
             if (!changed)
                 changed = !bseq(old, bb[i]->liveout);
+            bsfree(old);
         }
-        bsfree(old);
     }
 }
 
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -391,7 +391,7 @@
             return off;
         off += size(ty->sdecls[i]);
     }
-    return -1;
+    die("bad offset");
 }
 
 size_t size(Node *n)
--- a/mi/match.c
+++ b/mi/match.c
@@ -189,9 +189,10 @@
     for (i = 0; i < pat->expr.nargs; i++) {
         elt = pat->expr.args[i];
         for (j = 0; j < t->nval; j++) {
-            if (!strcmp(namestr(elt->expr.idx), namestr(t->val[j]->expr.idx)))
+            if (!strcmp(namestr(elt->expr.idx), namestr(t->val[j]->expr.idx))) {
                 t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
-            break;
+                break;
+            }
         }
     }
     return t;
@@ -357,9 +358,13 @@
 {
     Node *e;
     size_t i;
+    char *s;
+
     if (dt->patexpr) {
         e = dt->patexpr;
-        indentf(depth, "%s%s %s : %s\n", iswild ? "WILDCARD " : "", opstr[exprop(e)], dtnodestr(e), tystr(exprtype(e)));
+        s = tystr(exprtype(e));
+        indentf(depth, "%s%s %s : %s\n", iswild ? "WILDCARD " : "", opstr[exprop(e)], dtnodestr(e), s);
+        free(s);
     } 
     if (dt->cap)
         for (i = 0; i < dt->ncap; i++)
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -164,6 +164,7 @@
                     break;
                 case OTzarg:
                     snprintf(buf, sizeof buf, "%s", oppretty[exprop(n)]);
+                    break;
                 case OTmisc:
                     switch (exprop(n)) {
                         case Ovar:
@@ -191,6 +192,9 @@
                             snprintf(buf, sizeof buf, "%s:%s", d, t);
                             break;
                     }
+                default:
+		    snprintf(buf, sizeof buf, "%s", d);
+                    break;
             }
             free(t);
             free(t1);
@@ -1445,9 +1449,10 @@
             infersub(st, n, ret, sawret, &isconst);
             switch (args[0]->lit.littype) {
                 case Lfunc:
-                    infernode(st, &args[0]->lit.fnval, NULL, NULL); break;
+                    infernode(st, &args[0]->lit.fnval, NULL, NULL);
                     /* FIXME: env capture means this is non-const */
                     n->expr.isconst = 1;
+                    break;
                 default:
                     n->expr.isconst = 1;
                     break;
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -650,7 +650,7 @@
             isfloat = 1;
         else if (hexval(c) < 0 || hexval(c) > base)
             lfatal(curloc, "Integer digit '%c' outside of base %d", c, base);
-        if (nbuf >= sizeof buf) {
+        if (nbuf >= sizeof buf - 1) {
             buf[nbuf-1] = '\0';
             lfatal(curloc, "number %s... too long to represent", buf);
         }
--- a/parse/type.c
+++ b/parse/type.c
@@ -247,7 +247,7 @@
 
     t = mktype(loc, Tytuple);
     t->nsub = nsub;
-    t->sub = xalloc(nsub*sizeof(Type));
+    t->sub = xalloc(nsub*sizeof(Type*));
     for (i = 0; i < nsub; i++)
         t->sub[i] = sub[i];
     return t;
@@ -260,7 +260,7 @@
 
     t = mktype(loc, Tyfunc);
     t->nsub = nargs + 1;
-    t->sub = xalloc((1 + nargs)*sizeof(Type));
+    t->sub = xalloc((1 + nargs)*sizeof(Type*));
     t->sub[0] = ret;
     for (i = 0; i < nargs; i++)
         t->sub[i + 1] = nodetype(args[i]);
--- a/parse/use.c
+++ b/parse/use.c
@@ -1034,12 +1034,13 @@
     k = htkeys(st->dcl, &n);
     for (i = 0; i < n; i++) {
         s = getdcl(st, k[i]);
+        assert(s != NULL);
         if (s->decl.vis == Visintern || s->decl.vis == Visbuiltin)
             continue;
         /* trait functions get written out with their traits */
         if (s->decl.trait)
             continue;
-        if (s && s->decl.isgeneric)
+        if (s->decl.isgeneric)
             wrbyte(f, 'G');
         else
             wrbyte(f, 'D');