[LyX/master] brkstr2str_pos: avoid case where length is negative
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Sun Jan 23 18:23:14 UTC 2022
commit ec3a44fef59129ba4492ddf30de81fa329e631d5
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Sun Jan 23 19:34:11 2022 +0100
brkstr2str_pos: avoid case where length is negative
The string that Qt sees is not the original string, since we add
zero-width nonbreaking spaces around it, plus an override character to
force rendering direction. This means that translating positions
between these two representation can be a bit tricky.
We use a max(foo, 0) here to make sure that our intermediate
computation is postive.
Fixes part of bug #12452.
---
src/frontends/qt/GuiFontMetrics.cpp | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp
index d827f2f..e7f61c6 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -535,7 +535,7 @@ docstring::size_type brkstr2str_pos(QString brkstr, docstring const & str, int p
*/
// The variable `brkStrOffset' is here to account for the extra leading characters.
// The ending character zerow_nbsp has to be ignored if the line is complete.
- int const qlen = pos - brkStrOffset - (pos == brkstr.length());
+ int const qlen = max(pos - brkStrOffset - (pos == brkstr.length()), 0);
#if QT_VERSION < 0x040801 || QT_VERSION >= 0x050100
auto const len = qstring_to_ucs4(brkstr.mid(brkStrOffset, qlen)).length();
// Avoid warning
More information about the lyx-cvs
mailing list