diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a31339ab9..425db09d2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -593,7 +593,11 @@ void CheckOther::checkRedundantAssignment() if (tok == writtenArgumentsEnd) writtenArgumentsEnd = 0; - if (tok->str() == "{" && tok->strAt(-1) != "{" && tok->strAt(-1) != "=" && tok->strAt(-4) != "case" && tok->strAt(-3) != "default") { // conditional or non-executable inner scope: Skip it and reset status + if (tok->str() == "?" && tok->astOperand2()) { + tok = Token::findsimplematch(tok->astOperand2(), ";"); + varAssignments.clear(); + memAssignments.clear(); + } else if (tok->str() == "{" && tok->strAt(-1) != "{" && tok->strAt(-1) != "=" && tok->strAt(-4) != "case" && tok->strAt(-3) != "default") { // conditional or non-executable inner scope: Skip it and reset status tok = tok->link(); varAssignments.clear(); memAssignments.clear(); diff --git a/test/testother.cpp b/test/testother.cpp index 46740bf29..caaa6f3ac 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5591,6 +5591,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // #5964 + check("void func(char *buffer, const char *format, int precision, unsigned value) {\n" + " (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // don't crash check("struct data {\n" " struct { int i; } fc;\n"