Fixed false positive in CheckUnusedVar::checkFunctionVariableUsage(): Bailout when break; is encountered
See also: https://sourceforge.net/p/cppcheck/discussion/general/thread/1c169dc5/
This commit is contained in:
parent
d7bf0f4e4e
commit
3bdcf68990
|
@ -769,7 +769,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
variables.clear();
|
variables.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(tok, "goto")) { // https://sourceforge.net/apps/trac/cppcheck/ticket/4447
|
if (Token::Match(tok, "goto|break")) { // #4447
|
||||||
variables.clear();
|
variables.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3770,9 +3770,25 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return ptr;\n"
|
" return ptr;\n"
|
||||||
"}");
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str()); // Don't write an error that "a" is not used
|
||||||
|
|
||||||
// Don't write an error that "a" is not used
|
functionVariableUsage("void x() {\n"
|
||||||
ASSERT_EQUALS("", errout.str());
|
" unsigned char* pcOctet = NULL;\n"
|
||||||
|
" float fValeur;\n"
|
||||||
|
" switch (pnodeCurrent->left.pnode->usLen) {\n"
|
||||||
|
" case 4:\n"
|
||||||
|
" fValeur = (float)pevalDataLeft->data.fd;\n"
|
||||||
|
" pcOctet = (unsigned char*)&fValeur;\n"
|
||||||
|
" break;\n"
|
||||||
|
" case 8:\n"
|
||||||
|
" pcOctet = (unsigned char*)&pevalDataLeft->data.fd;\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
" for (iIndice = 1; iIndice <= (pnodeCurrent->usLen / 2); iIndice++) {\n"
|
||||||
|
" *pcData = gacHexChar[(*pcOctet >> 4) & 0x0F];\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str()); // Don't write an error that "fValeur" is not used
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe
|
void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe
|
||||||
|
|
Loading…
Reference in New Issue