shithub: neatroff

Download patch

ref: 15fdd6eed8b3fbf509de2dc11e4ea1ac7564d19b
parent: c380cf15117112369d834b462b6ed4355c902a33
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Jul 18 10:14:35 EDT 2014

ren: do not execute tr.c requests when a character is queued in ren.c

Functions like ren_tab() may push back a newline with ren_back().  If
tr_nextreq() is called unconditionally, the newline may be read in the
wrong order (after executing its following request).  The queued
newline may also result in pushing an extra newline with in_push() in
trap_exec().  This patch handles these cases.

Reported by Dirk-Wilhelm Peters <peters@schwertfische>.

--- a/ren.c
+++ b/ren.c
@@ -168,7 +168,7 @@
 static void trap_exec(int reg)
 {
 	char cmd[16];
-	int partial = ren_partial;
+	int partial = ren_partial && (!ren_un || ren_unbuf[0] != '\n');
 	if (str_get(reg)) {
 		sprintf(cmd, "%c%s %d\n", c_cc, TR_POPREN, ren_level);
 		in_push(cmd, NULL);
@@ -945,7 +945,7 @@
 {
 	int c;
 	while (ren_level >= level) {
-		while (!tr_nextreq())
+		while (!ren_un && !tr_nextreq())
 			if (ren_level < level)
 				break;
 		if (ren_level < level)