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

This commit is contained in:
Thomas Mannay 2016-10-09 23:10:20 +00:00 committed by Laslo Hunhold
parent d2bd40a589
commit 61e06396bd

8
ed.c
View File

@ -192,7 +192,9 @@ getindex(int line)
struct hline *lp; struct hline *lp;
int n; 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; lp = zero + lp->next;
return lp - zero; return lp - zero;
@ -806,9 +808,11 @@ join(void)
static char *s; static char *s;
free(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) for (t = gettxt(i); (c = *t) != '\n'; ++t)
s = addchar(*t, s, &cap, &len); s = addchar(*t, s, &cap, &len);
if (i == line2)
break;
} }
s = addchar('\n', s, &cap, &len); s = addchar('\n', s, &cap, &len);