shithub: mc

Download patch

ref: 0b419bf55a006dcee16bd9f50a4f8ec807437ce4
parent: 9bf6e6ac4a110b4b5597f90fb163922c613a9ea8
author: Ori Bernstein <[email protected]>
date: Fri Oct 26 11:00:13 EDT 2012

Don't recurse infinitely when pickling unions.

    The ucon contains a pointer back towards it's type. Pickling
    this pointer will cause infinite recursion.

    This is bad.

--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -91,13 +91,14 @@
     wrint(fd, uc->line);
     wrint(fd, uc->id);
     pickle(uc->name, fd);
-    wrtype(fd, uc->utype);
-    wrtype(fd, uc->etype);
+    wrbool(fd, uc->etype != NULL);
+    if (uc->etype)
+      wrtype(fd, uc->etype);
 }
 
-static Ucon *rducon(FILE *fd)
+static Ucon *rducon(FILE *fd, Type *ut)
 {
-    Type *ut, *et;
+    Type *et;
     Node *name;
     Ucon *uc;
     size_t id;
@@ -106,8 +107,8 @@
     line = rdint(fd);
     id = rdint(fd);
     name = unpickle(fd);
-    ut = rdtype(fd);
-    et = rdtype(fd);
+    if (rdbool(fd))
+      et = rdtype(fd);
     uc = mkucon(line, name, ut, et);
     uc->id = id;
     return uc;
@@ -251,7 +252,7 @@
             ty->nmemb = rdint(fd);
             ty->udecls = xalloc(ty->nmemb * sizeof(Node*));
             for (i = 0; i < ty->nmemb; i++)
-                ty->udecls[i] = rducon(fd);
+                ty->udecls[i] = rducon(fd, ty);
             break;
         case Tyarray:
             ty->sub[0] = rdtype(fd);