Bug hunting; Avoid bailout uninit FP, stream object
This commit is contained in:
parent
fe0081496c
commit
4a76dbb632
|
@ -269,6 +269,10 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
if (Token::Match(tok, "%var% .") && tok->next()->originalName() != "->")
|
if (Token::Match(tok, "%var% .") && tok->next()->originalName() != "->")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Assume that stream object is initialized
|
||||||
|
if (Token::Match(tok->previous(), "[;{}] %var% <<|>>") && !tok->next()->astParent())
|
||||||
|
return;
|
||||||
|
|
||||||
// Containers are not uninitialized
|
// Containers are not uninitialized
|
||||||
std::vector<const Token *> tokens{tok, tok->astOperand1(), tok->astOperand2()};
|
std::vector<const Token *> tokens{tok, tok->astOperand1(), tok->astOperand2()};
|
||||||
if (Token::Match(tok->previous(), ". %name%"))
|
if (Token::Match(tok->previous(), ". %name%"))
|
||||||
|
|
|
@ -2241,6 +2241,10 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
if (Token::Match(tok, "[;{}]"))
|
if (Token::Match(tok, "[;{}]"))
|
||||||
data.trackProgramState(tok);
|
data.trackProgramState(tok);
|
||||||
|
|
||||||
|
if (Token::simpleMatch(tok, "__CPPCHECK_BAILOUT__ ;"))
|
||||||
|
// This is intended for testing
|
||||||
|
throw ExprEngineException(tok, "__CPPCHECK_BAILOUT__");
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "while (") && (tok->linkAt(1), ") ;") && tok->next()->astOperand1()->hasKnownIntValue() && tok->next()->astOperand1()->getKnownIntValue() == 0) {
|
if (Token::simpleMatch(tok, "while (") && (tok->linkAt(1), ") ;") && tok->next()->astOperand1()->hasKnownIntValue() && tok->next()->astOperand1()->getKnownIntValue() == 0) {
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
TEST_CASE(uninit_function_par);
|
TEST_CASE(uninit_function_par);
|
||||||
TEST_CASE(uninit_malloc);
|
TEST_CASE(uninit_malloc);
|
||||||
TEST_CASE(uninit_struct);
|
TEST_CASE(uninit_struct);
|
||||||
|
TEST_CASE(uninit_bailout);
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctu);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -110,6 +111,22 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninit_bailout() {
|
||||||
|
check("void foo() {\n"
|
||||||
|
" __CPPCHECK_BAILOUT__;\n"
|
||||||
|
" int values[5];\n"
|
||||||
|
" values[i] = 123;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n"
|
||||||
|
" __CPPCHECK_BAILOUT__;\n"
|
||||||
|
" std::ostringstream comm;\n"
|
||||||
|
" comm << 123;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctu() {
|
||||||
check("void init(int &x) {\n"
|
check("void init(int &x) {\n"
|
||||||
" x = 1;\n"
|
" x = 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue