Handle ternary operator in redundantAssignment check (#5964)

This commit is contained in:
PKEuS 2014-09-01 23:16:52 +02:00
parent f94e208862
commit 00044aabb0
2 changed files with 11 additions and 1 deletions

View File

@ -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();

View File

@ -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"