From 54ad6d512bdd9b15553d9e1bd8be5c33e4561535 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" Date: Thu, 7 Jan 2016 11:37:56 +0100 Subject: [PATCH] Fix rematch() Rematch() was incremnenting the last match always, even in the cases when it was not matching anything. This patch detects this situation and it updates it only when there is a match. --- ed.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ed.c b/ed.c index e98acda..0fc07b1 100644 --- a/ed.c +++ b/ed.c @@ -404,8 +404,13 @@ match(int num) static int rematch(int num) { - lastmatch += matchs[0].rm_eo; - return !regexec(pattern, lastmatch, 10, matchs, 0); + regoff_t off = matchs[0].rm_eo; + + if (!regexec(pattern, lastmatch + off, 10, matchs, 0)) { + lastmatch += off; + return 1; + } + return 0; } static int