Stop matching when lastmatch points to '\n'

This situation happens with something like s/$/test/,
where rm_so == rm_eo == 0. Without this check, ed
keeps looping forever.
This commit is contained in:
Roberto E. Vargas Caballero 2016-01-07 12:34:40 +01:00 committed by sin
parent 0b117ab6c0
commit cf868c8eeb
1 changed files with 1 additions and 1 deletions

2
ed.c
View File

@ -1005,7 +1005,7 @@ subline(int num, int nth)
static size_t siz, cap;
i = changed = siz = 0;
for (m = match(num); m; m = rematch(num)) {
for (m = match(num); m && *lastmatch != '\n'; m = rematch(num)) {
addpre(&s, &cap, &siz);
changed |= addsub(&s, &cap, &siz, nth, ++i);
}