fix tracing output regression

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I introduced a latent bug in push_token in my argv_ref patch Stage 14 in
February, where I did not break the pointer from a cloned chain back into
the original chain when inlining the final element of the chain.  As long
as nothing accessed the chain until after push_string_finish, the stale
pointer was eventually corrected without anyone dereferencing it.  But
this bug then triggered a regression in Stage 23 in May, where trace was
changed to read the unfinished change, and thus the inlined link of the
chain appeared twice instead of once in trace output (the duplicate output
came from following the cloned chain back into the original chain,
followed by printing the inlined text).  Fixed as follows.  (Isn't it
strange how one line fixes the bug, and the bulk of the patch is merely
insurance that it doesn't relapse?)

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiQaAIACgkQ84KuGfSFAYArTACghj14D95x8/JsXAxRk5o8WLdq
Jz4AnRKE3wiYEjUzLCuyp3ZVUmjqaXTV
=meMg
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch366 (text/plain, 2.4 KB)
From c9d53ab9bcef0cb04d59f5797e6f20159150b75d Mon Sep 17 00:00:00 2001
From: Eric Blake <[email protected]>
Date: Wed, 30 Jul 2008 07:08:29 -0600
Subject: [PATCH] Fix regression in trace output, introduced 2008-05-09.

* src/input.c (push_token): When cloning chains, break pointer
back to original chain; latent bug from 2008-02-02 that did not
cause misbehavior until trace output read unfinished chain.
* doc/m4.texinfo (Trace): Add test for this.

Signed-off-by: Eric Blake <[email protected]>
---
 ChangeLog      |    8 ++++++++
 doc/m4.texinfo |   16 ++++++++++++++++
 src/input.c    |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 47449f2..d4f182e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-30  Eric Blake  <[email protected]>
+
+	Fix regression in trace output, introduced 2008-05-09.
+	* src/input.c (push_token): When cloning chains, break pointer
+	back to original chain; latent bug from 2008-02-02 that did not
+	cause misbehavior until trace output read unfinished chain.
+	* doc/m4.texinfo (Trace): Add test for this.
+
 2008-07-28  Eric Blake  <[email protected]>
 
 	Optimize iteration examples.
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index f8b3998..abacef9 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -3854,6 +3854,22 @@ indir(`my_defn', indir(`shift', `', `foo'))
 @result{}bar
 @end example
 
+@ignore
+@comment not worth including in the manual, but this tests a trace code
+@comment path that was temporarily broken
+@comment options: -de --trace ifelse
+@example
+$ @kbd{m4 -de --trace ifelse}
+define(`e', `ifelse(`$1', `$2', `ifelse(`$1', `$2', `e(shift($@@))')')')
+@result{}
+e(`1', `1')
+@error{}m4trace: -1- ifelse -> ifelse(`1', `1', `e(shift(`1',`1'))')
+@error{}m4trace: -1- ifelse -> e(shift(`1',`1'))
+@error{}m4trace: -1- ifelse ->@w{ }
+@result{}
+@end example
+@end ignore
+
 @node Debug Levels
 @section Controlling debugging output
 
diff --git a/src/input.c b/src/input.c
index 18271cd..0d08215 100644
--- a/src/input.c
+++ b/src/input.c
@@ -472,6 +472,7 @@ push_token (token_data *token, int level, bool inuse)
 	     destructively modifies the chain it is parsing.  */
 	  chain = (token_chain *) obstack_copy (current_input, src_chain,
 						sizeof *chain);
+	  chain->next = NULL;
 	  if (chain->type == CHAIN_STR && chain->u.u_s.level == -1)
 	    {
 	      if (chain->u.u_s.len <= INPUT_INLINE_THRESHOLD || !inuse)
-- 
1.5.6.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.