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: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
Thomas Hartmann
2016-11-25 14:53:06 +01:00
parent 22e6cf39ca
commit 95366d25e0

View File

@@ -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);