[hackers] [sbase][PATCH] ed: Fix j command bugs

From: Wolfgang Corcoran-Mathe <wcm_AT_sigwinch.xyz>
Date: Mon, 15 May 2017 17:42:57 -0400

Remove a double free() that caused joins to randomly segfault.
Fix a bug in delete() that occasionally caused lines to be
transposed.
---
 ed.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/ed.c b/ed.c
index e737d57..f6e195f 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -781,7 +781,7 @@ delete(int from, int to)
 	lfrom = getindex(prevln(from));
 	lto = getindex(nextln(to));
 	lastln -= to - from + 1;
-	curln = (from > lastln) ? lastln : from;;
+	curln = prevln(from);
 	relink(lto, lfrom, lto, lfrom);
 }
 
_AT_@ -819,7 +819,6 @@ join(void)
 	size_t len = 0, cap = 0;
 	static char *s;
 
-	free(s);
 	for (s = NULL, i = line1;; i = nextln(i)) {
 		for (t = gettxt(i); (c = *t) != '\n'; ++t)
 			s = addchar(*t, s, &cap, &len);
-- 
2.9.0
Received on Mon May 15 2017 - 23:42:57 CEST

This archive was generated by hypermail 2.3.0 : Mon May 15 2017 - 23:48:18 CEST