Fix a crash in the URL handling for the dive notes

URLs in the dive notes are detected today. A tooltip is displayed and
one can follow the URL by Ctrl-click.

In the function fromCursorTilWhitespace there is an issue with incorrect
return value of Qt (5.7?!) function cursor->movePosition(). This value is
erroneous true in some condition e.g. if the cursor is inside a table at
the very beginning or the very end of a table line and not moving any more.
This can cause the function end up in an infinite loop.

Bugfix adds an additional exit criteria for the loop if the string is
not growing any more.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
Stefan Fuchs 2017-04-18 23:35:43 +02:00 committed by Dirk Hohndel
parent 58a25d33ce
commit c257144bab

View file

@ -748,6 +748,7 @@ QString TextHyperlinkEventFilter::fromCursorTilWhitespace(QTextCursor *cursor, c
QString grownText;
QString noSpaces;
bool movedOk = false;
int oldSize = -1;
do {
result = grownText; // this is a no-op on the first visit.
@ -759,6 +760,8 @@ QString TextHyperlinkEventFilter::fromCursorTilWhitespace(QTextCursor *cursor, c
}
grownText = cursor->selectedText();
if (grownText.size() == oldSize) movedOk = false;
oldSize = grownText.size();
noSpaces = grownText.simplified().replace(" ", "");
} while (grownText == noSpaces && movedOk);