path: root/6
diff options
authorOri Bernstein <>2018-04-05 13:48:16 -0700
committerOri Bernstein <>2018-04-05 13:48:16 -0700
commit185f780a03fbfbb4655b7c07b3ac147980cede2d (patch)
treea0a13006d8390e4e04f0e46f938e0226901c3f45 /6
parent814c5bcd2efc3bb9139a56a1e0eae177437f4f56 (diff)
Ensure that we initialize the environment fully.
Initially, the thought was that since the function doesn't access any of the environment data, initializing it was a waste of time. This is true -- if the environment is not heapified. But we do often want to heapify the environment, which means that if we have junk in the environment pointer we will think, incorrectly, that there is an environment to duplicate. This leads to crashes. Crashes are a bad thing. This change zeroes out the environment pointer, so that we don't have crashes. This makes mpu happy(er).
Diffstat (limited to '6')
1 files changed, 9 insertions, 0 deletions
diff --git a/6/simp.c b/6/simp.c
index d2a9d18..803c5d3 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1006,6 +1006,15 @@ capture(Simp *s, Node *n, Node *dst)
envsz->expr.type = tyintptr;
assignat(s, e, 0, envsz);
assignat(s, fp, 0, e);
+ } else {
+ /*
+ * We need to zero out the environment, so that
+ * duplicating the function doesn't think we have
+ * a bogus environment.
+ */
+ e = mkintlit(n->loc, 0);
+ e->expr.type = tyintptr;
+ assignat(s, fp, 0, e);
assignat(s, fp, Ptrsz, f);
return dst;