From c5fa25b839e64ccb5dbb99e195c6898b5de870e0 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Mon, 26 Nov 2018 12:37:18 +0100 Subject: [PATCH] FindAdv: Avoid crash finding char at end of inset Testcase without this patch: 1.) open de/Additional.lyx 2.) goto 6.1 Astronomy & Astrophysics 3.) open the index 4.) find advaced a.) not ignoring format b.) regex = .+ c.) language of regex: English 4.) search next The seach finds the next break (which is outside of the index) The following try to display the selection leads to crash --- src/lyxfind.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 0bd647fff4..35be0d0143 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -2656,9 +2656,9 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) // Compute the match length int len = 1; + if (cur.pos() + len > cur.lastpos()) + return 0; if (match.opt.matchword) { - if (cur.pos() + len > cur.lastpos()) - return 0; LYXERR(Debug::FIND, "verifying unmatch with len = " << len); while (cur.pos() + len <= cur.lastpos() && match(cur, len) <= 0) { ++len; -- 2.39.5