This commit is contained in:
parent
774123d28d
commit
4c1e06a84b
|
@ -277,9 +277,10 @@ void CheckAutoVariables::autoVariables()
|
|||
errorInvalidDeallocation(tok, nullptr);
|
||||
else if (tok->variable() && tok->variable()->isPointer()) {
|
||||
for (const ValueFlow::Value &v : tok->values()) {
|
||||
if (!(v.isTokValue()))
|
||||
if (v.isImpossible())
|
||||
continue;
|
||||
if (isArrayVar(v.tokvalue) || ((v.tokvalue->tokType() == Token::eString) && !v.isImpossible())) {
|
||||
if ((v.isTokValue() && (isArrayVar(v.tokvalue) || ((v.tokvalue->tokType() == Token::eString)))) ||
|
||||
(v.isLocalLifetimeValue() && v.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)) {
|
||||
errorInvalidDeallocation(tok, &v);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -793,6 +793,23 @@ private:
|
|||
"};\n"
|
||||
"Array arr;\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #8174
|
||||
check("struct S {};\n"
|
||||
"void f() {\n"
|
||||
" S s;\n"
|
||||
" S* p = &s;\n"
|
||||
" free(p);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Deallocation of an auto-variable (s) results in undefined behaviour.\n", errout.str());
|
||||
|
||||
check("void f(bool b, int* q) {\n"
|
||||
" int i;\n"
|
||||
" int* p = b ? &i : q;\n"
|
||||
" if (!b)\n"
|
||||
" free(p);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testinvaliddealloc_input() {
|
||||
|
|
Loading…
Reference in New Issue