changeset 192:255db24bc29b

Fix output corruption; see CHANGES entry.
author David A. Holland
date Fri, 12 Jun 2015 21:54:32 -0400
parents c8d4ab9aeff0
children 079304130850
files CHANGES macro.c
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Fri Jun 12 20:06:55 2015 -0400
+++ b/CHANGES	Fri Jun 12 21:54:32 2015 -0400
@@ -1,4 +1,10 @@
 pending
+   - Fix output corruption caused by mishandling which macros are
+     currently in use. In particular, "curmacro" is only valid while
+     we're parsing a macro name and arguments, and can change once we
+     start expanding, so don't use it to clear the in-use flag.
+   - Also don't set curmacro to null after calling expand_domacro as
+     that can cause us to think a macro name we just read is defined().
    - Don't use "remove" as a local variable as gcc 4.1 gets upset
      about it vs. remove(3) in stdio.h.
 
--- a/macro.c	Fri Jun 12 20:06:55 2015 -0400
+++ b/macro.c	Fri Jun 12 21:54:32 2015 -0400
@@ -892,8 +892,9 @@
 		return;
 	}
 
-	assert(es->curmacro->inuse == false);
-	es->curmacro->inuse = true;
+	m = es->curmacro;
+	assert(m->inuse == false);
+	m->inuse = true;
 
 	newbuf = expand_substitute(p, es);
 	newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false);
@@ -902,7 +903,7 @@
 	doexpand(es, p, newbuf2, strlen(newbuf2));
 	dostrfree(newbuf2);
 
-	es->curmacro->inuse = false;
+	m->inuse = false;
 }
 
 /*
@@ -970,7 +971,6 @@
 		} else if (!m->hasparams) {
 			es->curmacro = m;
 			expand_domacro(es, p);
-			es->curmacro = NULL;
 		} else {
 			es->curmacro = m;
 			es->state = ES_WANTLPAREN;