Fixed #5274 (TokenList: macro handling)
This commit is contained in:
parent
cbe3862599
commit
7125682d1a
|
@ -761,7 +761,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||||
// - logical operators
|
// - logical operators
|
||||||
const Token* tok = i->classDef;
|
const Token* tok = i->classDef;
|
||||||
if ((i->type == Scope::eIf || i->type == Scope::eElseIf || i->type == Scope::eWhile) &&
|
if ((i->type == Scope::eIf || i->type == Scope::eElseIf || i->type == Scope::eWhile) &&
|
||||||
tok && Token::Match(tok, "else| %var% ( !| %var% )|%oror%|&&") && !tok->next()->isExpandedMacro()) {
|
tok && Token::Match(tok, "else| %var% ( !| %var% )|%oror%|&&") && !tok->tokAt(tok->str()=="else"?1:0)->isExpandedMacro()) {
|
||||||
|
|
||||||
if (tok->str() == "else")
|
if (tok->str() == "else")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -199,10 +199,13 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
if (ch == Preprocessor::macroChar) {
|
if (ch == Preprocessor::macroChar) {
|
||||||
while (code.peek() == Preprocessor::macroChar)
|
while (code.peek() == Preprocessor::macroChar)
|
||||||
code.get();
|
code.get();
|
||||||
ch = ' ';
|
if (!CurrentToken.empty()) {
|
||||||
|
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
||||||
|
_back->isExpandedMacro(expandedMacro);
|
||||||
|
}
|
||||||
|
CurrentToken.clear();
|
||||||
expandedMacro = true;
|
expandedMacro = true;
|
||||||
} else if (ch == '\n') {
|
continue;
|
||||||
expandedMacro = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// char/string..
|
// char/string..
|
||||||
|
@ -317,8 +320,10 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
}
|
}
|
||||||
|
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
||||||
if (!CurrentToken.empty())
|
if (!CurrentToken.empty()) {
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
|
expandedMacro = false;
|
||||||
|
}
|
||||||
|
|
||||||
CurrentToken.clear();
|
CurrentToken.clear();
|
||||||
|
|
||||||
|
@ -339,6 +344,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex);
|
addtoken(CurrentToken.c_str(), lineno, FileIndex);
|
||||||
_back->isExpandedMacro(expandedMacro);
|
_back->isExpandedMacro(expandedMacro);
|
||||||
CurrentToken.clear();
|
CurrentToken.clear();
|
||||||
|
expandedMacro = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -498,7 +498,7 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning, inconclusive) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning, inconclusive) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// false positives when there are macros
|
// #3425 - false positives when there are macros
|
||||||
check("void f(struct FRED *fred) {\n"
|
check("void f(struct FRED *fred) {\n"
|
||||||
" fred->x = 0;\n"
|
" fred->x = 0;\n"
|
||||||
" $if(!fred){}\n"
|
" $if(!fred){}\n"
|
||||||
|
@ -822,7 +822,7 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// false positives when there are macros
|
// #3425 - false positives when there are macros
|
||||||
check("void f(int *p) {\n"
|
check("void f(int *p) {\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
" $if(!p){}\n"
|
" $if(!p){}\n"
|
||||||
|
|
|
@ -773,7 +773,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void tokenize22() { // tokenize special marker $ from preprocessor
|
void tokenize22() { // tokenize special marker $ from preprocessor
|
||||||
ASSERT_EQUALS("$a $b", tokenizeAndStringify("a$b"));
|
ASSERT_EQUALS("a $b", tokenizeAndStringify("a$b"));
|
||||||
|
ASSERT_EQUALS("a $b\nc", tokenizeAndStringify("a $b\nc"));
|
||||||
|
ASSERT_EQUALS("a = $0 ;", tokenizeAndStringify("a = $0;"));
|
||||||
|
ASSERT_EQUALS("a $++ ;", tokenizeAndStringify("a$++;"));
|
||||||
|
ASSERT_EQUALS("$if ( ! p )", tokenizeAndStringify("$if(!p)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
|
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
|
||||||
|
|
Loading…
Reference in New Issue