Fixed #2585 (segmentation fault of cppcheck (CheckOther::clarifyCalculation))
This commit is contained in:
parent
cf2a04377e
commit
dfba4b7332
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue