Fixed #3544 (segmentation fault of cppcheck)
This commit is contained in:
parent
0cf2c2b327
commit
e146591b5d
|
@ -116,6 +116,9 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last,
|
|||
if (tok2->str() == "(" || tok2->str() == "[" || tok2->str() == "{")
|
||||
links.push(tok2);
|
||||
else if (tok2->str() == ")" || tok2->str() == "]" || tok2->str() == "}") {
|
||||
if (links.empty())
|
||||
return tok2;
|
||||
|
||||
Token * link = links.top();
|
||||
|
||||
tok2->link(link);
|
||||
|
|
|
@ -60,6 +60,7 @@ private:
|
|||
// don't freak out when the syntax is wrong
|
||||
TEST_CASE(wrong_syntax1);
|
||||
TEST_CASE(wrong_syntax2);
|
||||
TEST_CASE(wrong_syntax3); // #3544
|
||||
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO()
|
||||
|
||||
TEST_CASE(minus);
|
||||
|
@ -658,6 +659,18 @@ private:
|
|||
tokenizeAndStringify(code);
|
||||
}
|
||||
|
||||
void wrong_syntax3() { // #3544
|
||||
const char code[] = "X #define\n"
|
||||
"{\n"
|
||||
" (\n"
|
||||
" for( #endif typedef typedef cb[N] )\n"
|
||||
" ca[N]; = cb[i]\n"
|
||||
" )\n"
|
||||
"}";
|
||||
|
||||
tokenizeAndStringify(code);
|
||||
}
|
||||
|
||||
void wrong_syntax_if_macro() {
|
||||
// #2518
|
||||
const std::string code("void f() { if MACRO(); }");
|
||||
|
|
Loading…
Reference in New Issue