Commit 95366d25 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlJS: Fix crash in QML reformatter

This fixes a tack overflow caused by an exponential
number of combination tested.

We try to find the optimal solution for line breaks by brute force.
Unfortunately this leads to a stack overflow, if two many
line breaks are possible.

This patch limits the number of possible line break positions to 11.
If there are more possible line breaks we remove every second one.

This seems to be a reasonable enough heuristic and we deal with
a corner case anyway.

Task-number: QTCREATORBUG-17331
Change-Id: I1b80fc3eaa0e148aec30fc57ac75824181f2d883
Reviewed-by: default avatarMarco Benelli <marco.benelli@qt.io>
parent 22e6cf39
......@@ -282,6 +282,15 @@ protected:
{
BestSplit result;
while (possibleSplits.count() > 12) {
QList<Split> newPossibleSplits;
for (int i = 0; i < possibleSplits.count(); i++) {
if (!(i % 2))
newPossibleSplits.push_back(possibleSplits.at(i));
}
possibleSplits = newPossibleSplits;
}
result.badnessFromSplits = 0;
result.lines = QStringList(line);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment