From 88abeeebba5cad4c19a3a772f502faf4aaa19200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 27 Jan 2011 21:16:25 +0100 Subject: [PATCH] Fixed #2518 (Crash when checking rockbox's firmwire) --- lib/tokenize.cpp | 10 ++++++++++ test/testtokenize.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d21484c52..bdbb6e44b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2041,6 +2041,16 @@ bool Tokenizer::tokenize(std::istream &code, } } + // if MACRO + for (const Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::Match(tok, "if|for|while %var% (")) + { + syntaxError(tok); + return false; + } + } + // Simplify JAVA/C# code if (isJavaOrCSharp() && _files[0].find(".java") != std::string::npos) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 561b91a95..d252696c3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -52,6 +52,7 @@ private: // don't freak out when the syntax is wrong TEST_CASE(wrong_syntax); + TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO() TEST_CASE(minus); @@ -522,6 +523,15 @@ private: } } + void wrong_syntax_if_macro() + { + // #2518 + errout.str(""); + const std::string code("void f() { if MACRO(); }"); + tokenizeAndStringify(code.c_str(), false); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } + void minus() { ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));