C++: Fix crash when #if[def] nesting is deeper than 512 levels

Change-Id: I5e86da3a36514545834f554470b147ad8be43344
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-02-03 09:10:37 +02:00
committed by Nikolai Kosjar
parent d7e5d41494
commit 75a943ef57
2 changed files with 40 additions and 5 deletions

View File

@@ -390,6 +390,7 @@ private slots:
void empty_trailing_lines_data();
void undef();
void concat();
void excessive_nesting();
};
// Remove all #... lines, and 'simplify' string, to allow easily comparing the result
@@ -1895,6 +1896,23 @@ void tst_Preprocessor::concat()
QCOMPARE(prep.constData(), output.constData());
}
void tst_Preprocessor::excessive_nesting()
{
Environment env;
Preprocessor preprocess(0, &env);
QByteArray input;
const QByteArray output =
"# 1 \"<stdin>\"\n"
"# 2001 \"<stdin>\"\n";
for (int i = 0; i < 1000; ++i)
input += "#if FOO\n";
for (int i = 0; i < 1000; ++i)
input += "#endif\n";
QByteArray prep = preprocess.run(QLatin1String("<stdin>"), input);
// Output cannot be precisely determined, but it shouldn't crash.
QCOMPARE(prep, output);
}
void tst_Preprocessor::compare_input_output(bool keepComments)
{
QFETCH(QByteArray, input);