This commit is contained in:
chrchr-github 2022-07-18 18:03:08 +02:00 committed by GitHub
parent cc9c5a2768
commit 6dc606fd6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -3947,6 +3947,22 @@ private:
" f(bar);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
check("class Foo {};\n" // #10750
"struct Bar {\n"
" Foo *_foo;\n"
"};\n"
"int f(Bar *bar);\n"
"void g(Bar *bar) {\n"
" {\n"
" Foo foo;\n"
" {\n"
" bar->_foo = &foo;\n"
" }\n"
" }\n"
" f(bar);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
}
void deadPointer() {

View File

@ -4219,6 +4219,15 @@ private:
" if (i == 1) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:20]: (style) Condition 'i==1' is always true\n", errout.str());
check("typedef struct { bool x; } s_t;\n" // #8446
"unsigned f(bool a, bool b) {\n"
" s_t s;\n"
" const unsigned col = a ? (s.x = false) : (b = true);\n"
" if (!s.x) {}\n"
" return col;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueSymbolic()

View File

@ -3292,6 +3292,16 @@ private:
" auto b { RAII() };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("struct RAIIWrapper {\n" // #10894
" RAIIWrapper();\n"
" ~RAIIWrapper();\n"
"};\n"
"static void foo() {\n"
" auto const guard = RAIIWrapper();\n"
" auto const& guard2 = RAIIWrapper();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvar47() { // #6603