diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f75f5f83f..233f562a8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index bdd9261af..428e77ba2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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()