shithub: mc

Download patch

ref: 185f780a03fbfbb4655b7c07b3ac147980cede2d
parent: 814c5bcd2efc3bb9139a56a1e0eae177437f4f56
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Apr 5 09:48:16 EDT 2018

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).

--- a/6/simp.c
+++ b/6/simp.c
@@ -1006,6 +1006,15 @@
 		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;