[hackers] [sbase] ed: remove infinite loops in join() and getindex() || Thomas Mannay

From: <git_AT_suckless.org>
Date: Tue, 27 Dec 2016 15:04:01 +0100 (CET)

commit 61e06396bdea2352b602a46a2ff7fcd627d073cb
Author: Thomas Mannay <audiobarrier_AT_openmailbox.org>
AuthorDate: Sun Oct 9 23:10:20 2016 +0000
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Dec 27 12:50:03 2016 +0100

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

diff --git a/ed.c b/ed.c
index 582a5a2..c4cce37 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);
Received on Tue Dec 27 2016 - 15:04:01 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 27 2016 - 15:12:46 CET