sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 61e06396bdea2352b602a46a2ff7fcd627d073cb
parent d2bd40a5890dbedef265228701cc42ac96219262
Author: Thomas Mannay <audiobarrier@openmailbox.org>
Date:   Sun,  9 Oct 2016 23:10:20 +0000

ed: remove infinite loops in join() and getindex()

Diffstat:
Med.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ed.c b/ed.c @@ -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; @@ -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);