mirror of
git://git.suckless.org/sbase
synced 2026-01-26 21:52:15 +00:00
ed: Detect correctly end of file in gettxt()
The function gettxt() is basically a repeat loop where it loops until it arrives to the end of the file when it doesn't find a newline, but the condition to detect the end of file was wrong and it looped forever in a file without newline.
This commit is contained in:
parent
c63dd6d499
commit
beb6a2fa2a
3
ed.c
3
ed.c
@ -244,6 +244,7 @@ gettxt(int line)
|
||||
return addchar('\0', &text);
|
||||
|
||||
repeat:
|
||||
chksignals();
|
||||
if (!csize || off < lasto || off - lasto >= csize) {
|
||||
block = off & ~(CACHESIZ-1);
|
||||
if (lseek(scratch, block, SEEK_SET) < 0 ||
|
||||
@ -257,7 +258,7 @@ repeat:
|
||||
++off;
|
||||
addchar(*p, &text);
|
||||
}
|
||||
if (csize && p == buf + csize)
|
||||
if (csize == CACHESIZ && p == buf + csize)
|
||||
goto repeat;
|
||||
|
||||
addchar('\n', &text);
|
||||
|
||||
13
tests/0007-ed.sh
Executable file
13
tests/0007-ed.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
tmp=tmp.$$
|
||||
|
||||
trap 'rm -f $tmp' EXIT
|
||||
trap 'rm -f $tmp; kill -KILL $$' HUP INT TERM
|
||||
|
||||
printf 'something important' > $tmp
|
||||
ed $tmp <<EOF 2>/dev/null | grep something | diff -w $tmp -
|
||||
1p
|
||||
EOF
|
||||
Loading…
x
Reference in New Issue
Block a user