Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Text: avoid crash by testing bounds for cursor pos.

Wolthera van Hövell tot Westerflier5d676f657da2
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 4f87d92271..c579350b44 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -391,7 +391,7 @@ int KoSvgTextShape::nextIndex(int pos)
if (d->cursorPos.isEmpty()) {
return pos;
}
- int currentIndex = d->cursorPos.at(pos).index;
+ int currentIndex = d->cursorPos.at(qBound(0, pos, d->cursorPos.size())).index;
for (int i = pos; i < d->cursorPos.size(); i++) {
if (d->cursorPos.at(i).index > currentIndex) {
@@ -406,7 +406,7 @@ int KoSvgTextShape::previousIndex(int pos)
if (d->cursorPos.isEmpty()) {
return pos;
}
- int currentIndex = d->cursorPos.at(pos).index;
+ const int currentIndex = d->cursorPos.at(qBound(0, pos, d->cursorPos.size())).index;
for (int i = pos; i >= 0; i--) {
if (d->cursorPos.at(i).index < currentIndex) {