[hackers] [PATCH 13/17] Fix copy()

From: quinq <quinq_AT_fifth.space>
Date: Tue, 6 Mar 2018 12:58:05 +0100

From: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>

Copy was using directly the line numbers and incrementing them
without calling to nextln(). It also didn't worried about how
line numbers are modified when we insert new lines.
---
 ed.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/ed.c b/ed.c
index 70dd2a5..13c41c6 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -854,14 +854,19 @@ scroll(int num)
 static void
 copy(int where)
 {
-	int i;
 
 	if (!line1)
 		error("incorrect address");
 	curln = where;
 
-	for (i = line1; i <= line2; ++i)
-		inject(gettxt(i), AFTER);
+	while (line1 <= line2) {
+		inject(gettxt(line1), AFTER);
+		if (line2 >= curln)
+			line2 = nextln(line2);
+		line1 = nextln(line1);
+		if (line1 >= curln)
+			line1 = nextln(line1);
+	}
 }
 
 static void
-- 
2.14.2
Received on Tue Mar 06 2018 - 12:58:05 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 06 2018 - 13:03:09 CET