ed

simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs | LICENSE

commit 0e3e318245c9265a6f81e91985b5de3e81205c24
parent 520a6bb3849813923d8ba7c9e7632dbafe71e6cf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat Nov 28 20:26:20 +0100

Avoid infinite loops in gettxt

Gettxt was checking that a full line could be read,
but in an empty line, the line 0 can not have a '\n',
so gettxt entered in an infinite loop, because
it was not able to read more bytes.
This condition could only appear in line 0 in an empty
file because we were forcing all the lines to have a
'\n'.

Diffstat:
ed.c | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/ed.c b/ed.c @@ -159,6 +159,8 @@ repeat: csize = n; lasto = block; } + if (csize == 0) + goto add_newline; for (p = &buf[off - lasto]; *p != '\n' && p < &buf[csize]; ++p) { ++off; addchar(*p); @@ -166,6 +168,7 @@ repeat: if (p == &buf[csize]) goto repeat; +add_newline: addchar('\n'); addchar('\0'); return text;