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;
|
return;
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (tok->str() == "?")
|
if (tok->strAt(1) == "?")
|
||||||
{
|
{
|
||||||
// condition
|
// condition
|
||||||
const Token *cond = tok->previous();
|
const Token *cond = tok;
|
||||||
if (cond->isName() || cond->isNumber())
|
if (cond->isName() || cond->isNumber())
|
||||||
cond = cond->previous();
|
cond = cond->previous();
|
||||||
else if (cond->str() == ")")
|
else if (cond->str() == ")")
|
||||||
|
@ -85,7 +85,7 @@ void CheckOther::clarifyCalculation()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// multiplication
|
// multiplication
|
||||||
if (cond->str() == "*")
|
if (cond && cond->str() == "*")
|
||||||
cond = cond->previous();
|
cond = cond->previous();
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1865,6 +1865,12 @@ private:
|
||||||
" printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n"
|
" printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (information) Please clarify precedence: 'a*b?..'\n", errout.str());
|
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()
|
void incorrectStringCompare()
|
||||||
|
|
Loading…
Reference in New Issue