Co-authored-by: chrchr-github <chrchr@github>
This commit is contained in:
parent
3272a2bbe7
commit
55c2b75c2e
|
@ -3257,6 +3257,11 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
|
||||||
return ExprUsage::Used;
|
return ExprUsage::Used;
|
||||||
} else if (ftok->str() == "{") {
|
} else if (ftok->str() == "{") {
|
||||||
return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive;
|
return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive;
|
||||||
|
} else if (ftok->variable() && ftok == ftok->variable()->nameToken()) { // variable init/constructor call
|
||||||
|
if (ftok->variable()->type() && ftok->variable()->type()->needInitialization == Type::NeedInitialization::True)
|
||||||
|
return ExprUsage::Used;
|
||||||
|
if (ftok->variable()->isStlType() || (ftok->variable()->valueType() && ftok->variable()->valueType()->container)) // STL types or containers don't initialize external variables
|
||||||
|
return ExprUsage::Used;
|
||||||
} else {
|
} else {
|
||||||
const bool isnullbad = settings->library.isnullargbad(ftok, argnr + 1);
|
const bool isnullbad = settings->library.isnullargbad(ftok, argnr + 1);
|
||||||
if (indirect == 0 && astIsPointer(tok) && !addressOf && isnullbad)
|
if (indirect == 0 && astIsPointer(tok) && !addressOf && isnullbad)
|
||||||
|
|
|
@ -321,6 +321,13 @@ void duplicateExpression_QString_Compare(QString style) //#8723
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QVector_uninit()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
// cppcheck-suppress [uninitvar, unreadVariable]
|
||||||
|
QVector<int> v(i);
|
||||||
|
}
|
||||||
|
|
||||||
void QStack1(QStack<int> intStackArg)
|
void QStack1(QStack<int> intStackArg)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= intStackArg.size(); ++i) {
|
for (int i = 0; i <= intStackArg.size(); ++i) {
|
||||||
|
|
|
@ -1043,8 +1043,8 @@ void uninitvar_isxdigit(void)
|
||||||
void uninitvar_proj(void)
|
void uninitvar_proj(void)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
|
// cppcheck-suppress uninitvar
|
||||||
const std::complex<double> dc(d,d);
|
const std::complex<double> dc(d,d);
|
||||||
// TODO cppcheck-suppress uninitvar
|
|
||||||
(void)std::proj(dc);
|
(void)std::proj(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7251,6 +7251,24 @@ private:
|
||||||
"[test.cpp:23]: (error) Uninitialized variable: s.t.j\n"
|
"[test.cpp:23]: (error) Uninitialized variable: s.t.j\n"
|
||||||
"[test.cpp:27]: (error) Uninitialized variable: s.t.j\n",
|
"[test.cpp:27]: (error) Uninitialized variable: s.t.j\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("struct S { int x; };\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" S s(i);\n"
|
||||||
|
"}\n"
|
||||||
|
"void g() {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" S t{ i };\n"
|
||||||
|
"}\n"
|
||||||
|
"void h() {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" std::vector<int> v(i);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n"
|
||||||
|
"[test.cpp:8]: (error) Uninitialized variable: i\n"
|
||||||
|
"[test.cpp:12]: (error) Uninitialized variable: i\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitvar_memberfunction() {
|
void uninitvar_memberfunction() {
|
||||||
|
|
Loading…
Reference in New Issue