Fixed #2585 (segmentation fault of cppcheck (CheckOther::clarifyCalculation))

This commit is contained in:
Daniel Marjamäki 2011-02-17 21:30:59 +01:00
parent cf2a04377e
commit dfba4b7332
2 changed files with 9 additions and 3 deletions

View File

@ -73,10 +73,10 @@ void CheckOther::clarifyCalculation()
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() == "?")
if (tok->strAt(1) == "?")
{
// condition
const Token *cond = tok->previous();
const Token *cond = tok;
if (cond->isName() || cond->isNumber())
cond = cond->previous();
else if (cond->str() == ")")
@ -85,7 +85,7 @@ void CheckOther::clarifyCalculation()
continue;
// multiplication
if (cond->str() == "*")
if (cond && cond->str() == "*")
cond = cond->previous();
else
continue;

View File

@ -1865,6 +1865,12 @@ private:
" printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (information) Please clarify precedence: 'a*b?..'\n", errout.str());
// Ticket #2585 - segmentation fault for invalid code
check("abcdef?" "?<"
"123456?" "?>"
"+?" "?=");
ASSERT_EQUALS("", errout.str());
}
void incorrectStringCompare()