From cf868c8eeb45f47063cc5d30b04b552e7dd5a7c4 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" Date: Thu, 7 Jan 2016 12:34:40 +0100 Subject: [PATCH] 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. --- ed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ed.c b/ed.c index 67ffdb8..4a872ed 100644 --- a/ed.c +++ b/ed.c @@ -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); }