# HG changeset patch # User David A. Holland # Date 1434160472 14400 # Node ID 255db24bc29bbaf2a9cfbf53267cd86aa6d0a79d # Parent c8d4ab9aeff0ac421d77942971da0516d8133062 Fix output corruption; see CHANGES entry. diff -r c8d4ab9aeff0 -r 255db24bc29b CHANGES --- 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. diff -r c8d4ab9aeff0 -r 255db24bc29b macro.c --- 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;