[hackers] [sbase] Fix rematch() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 11 Jan 2016 16:38:03 +0100 (CET)

commit 54ad6d512bdd9b15553d9e1bd8be5c33e4561535
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jan 7 11:37:56 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Jan 11 15:37:58 2016 +0000

    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.

diff --git a/ed.c b/ed.c
index e98acda..0fc07b1 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -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
Received on Mon Jan 11 2016 - 16:38:03 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 11 2016 - 16:48:18 CET