Commit 6d04f3ce authored by hjk's avatar hjk Committed by hjk
Browse files

preprocessor: do not loop endlessly on incomplete expressions



An missing closing parantheses after "defined(..." caused an endless loop.

Change-Id: I19b17cebc1a56880216c3bfb67c9d296f80cc064
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent 9ac204bd
......@@ -654,12 +654,12 @@ void Preprocessor::handleDefined(PPToken *tk)
break;
} while (isValidToken(*tk));
if (lparenSeen) {
while (tk->isNot(T_RPAREN))
lex(tk);
} else {
pushToken(tk);
}
if (lparenSeen && tk->is(T_RPAREN))
lex(tk);
pushToken(tk);
QByteArray result(1, '0');
if (m_env->resolve(idToken.asByteArrayRef()))
result[0] = '1';
......
......@@ -886,6 +886,26 @@ void tst_Preprocessor::defined_data()
"#if X <= 0x040000\n"
"#define Y 1\n"
"#endif\n";
QTest::newRow("incomplete defined 1") << true << true <<
"#define X 0x040500\n"
"#if defined(X\n"
"#define Y 1\n"
"#endif\n";
QTest::newRow("incomplete defined 2") << false << false <<
"#if defined(X\n"
"#define Y 1\n"
"#endif\n";
QTest::newRow("complete defined 1") << true << true <<
"#define X 0x040500\n"
"#if defined(X )\n"
"#define Y 1\n"
"#endif\n";
QTest::newRow("complete defined 2") << true << true <<
"#define X 0x040500\n"
"#if defined(X/*xxx*/)\n"
"#define Y 1\n"
"#endif\n";
}
QTEST_APPLESS_MAIN(tst_Preprocessor)
......
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