[PATCH 1/5] ed: remove infinite loops in join() and getindex()

From: Thomas Mannay <audiobarrier_AT_openmailbox.org>
Date: Sun, 9 Oct 2016 23:10:20 +0000

---
 ed.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/ed.c b/ed.c
index 184ed30..f552234 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -192,7 +192,9 @@ getindex(int line)
 	struct hline *lp;
 	int n;
 
-	for (n = 0, lp = zero; n != line; ++n)
+	if (line == -1)
+		line = 0;
+	for (n = 0, lp = zero; n != line; n++)
 		lp = zero + lp->next;
 
 	return lp - zero;
_AT_@ -806,9 +808,11 @@ join(void)
 	static char *s;
 
 	free(s);
-	for (s = NULL, i = line1; i <= line2; i = nextln(i)) {
+	for (s = NULL, i = line1;; i = nextln(i)) {
 		for (t = gettxt(i); (c = *t) != '\n'; ++t)
 			s = addchar(*t, s, &cap, &len);
+		if (i == line2)
+			break;
 	}
 
 	s = addchar('\n', s, &cap, &len);
-- 
2.10.0
--Multipart=_Sun__9_Oct_2016_23_20_20_+0000_Tw0GY2bnCixoZsD5
Content-Type: text/x-patch;
 name="0002-ed-giving-j-only-one-address-does-nothing.patch"
Content-Disposition: attachment;
 filename="0002-ed-giving-j-only-one-address-does-nothing.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Oct 10 2016 - 16:36:12 CEST