From 1518f6ba33780193e7eab694a000ae05f4528359 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 26 Jan 2024 19:41:23 +0100 Subject: Fix potential UTF-8 bugs --- src/grab.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/grab.c b/src/grab.c index 13a6e83..56d0442 100644 --- a/src/grab.c +++ b/src/grab.c @@ -463,8 +463,10 @@ cmdH(struct sv sv, struct matches *ms, struct ops ops, size_t i, } prev = rm; - if (rm.rm_so == rm.rm_eo) - rm.rm_eo++; + if (rm.rm_so == rm.rm_eo) { + rune unused; + rm.rm_eo += u8tor_uc(&unused, sv.p + rm.rm_eo); + } rm = (regmatch_t){ .rm_so = rm.rm_eo, .rm_eo = sv.len, @@ -554,8 +556,10 @@ cmdX(struct sv sv, struct matches *ms, struct ops ops, size_t i, } prev = rm; - if (rm.rm_so == rm.rm_eo) - rm.rm_eo++; + if (rm.rm_so == rm.rm_eo) { + rune unused; + rm.rm_eo += u8tor_uc(&unused, sv.p + rm.rm_eo); + } rm = (regmatch_t){ .rm_so = rm.rm_eo, .rm_eo = sv.len, -- cgit v1.2.3