diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 3051a9932..3da422400 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3571,6 +3571,19 @@ private: " for (const auto& s : a) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("std::vector f(const std::vector& args) {\n" // #9773 + " std::vector cargs;\n" + " for (const auto& a : args) {\n" + " cargs.push_back(const_cast(a.data()));\n" + " }\n" + " return cargs;\n" + "}\n" + "void g() {\n" + " std::vector cargs = f({ \"0\", \"0\" });\n" + " (void)cargs;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using object that is a temporary.\n", errout.str()); } void danglingLifetimeBorrowedMembers() diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index f595a0b42..8485db656 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -656,6 +656,12 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(std::string a, std::string b) {\n" // #7529 + " const std::string s = \" x \" + a;\n" + " +\" y = \" + b;\n" + "}\n", /*inconclusive*/ true); + ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n", errout.str()); } void vardecl() { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fc19c4081..a2a9064cd 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2041,6 +2041,20 @@ private: " return NewT(s);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("typedef struct s { char* str; } attr_t;\n" // #10152 + "attr_t* f(int type) {\n" + " attr_t a;\n" + " switch (type) {\n" + " case 1:\n" + " a.str = strdup(\"?\");\n" + " break;\n" + " default:\n" + " return NULL;\n" + " }\n" + " return g(&a);\n" + "}\n"); + TODO_ASSERT_EQUALS("", "[test.cpp:9]: (error) Memory leak: a.str\n", errout.str()); } void ifelse() { diff --git a/test/testother.cpp b/test/testother.cpp index 10a27fc78..36ffa85c1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5978,8 +5978,8 @@ private: errout.str()); } - void duplicateExpression16() { //#10569 - check("void f(const std::string& a) {\n" + void duplicateExpression16() { + check("void f(const std::string& a) {\n" //#10569 " if ((a == \"x\") ||\n" " (a == \"42\") ||\n" " (a == \"y\") ||\n" @@ -6001,6 +6001,14 @@ private: "[test.cpp:7] -> [test.cpp:9]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators.\n" "[test.cpp:13] -> [test.cpp:16]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators.\n", errout.str()); + + check("void f(const char* s) {\n" // #6371 + " if (*s == '\x0F') {\n" + " if (!s[1] || !s[2] || !s[1])\n" + " break;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators.\n", errout.str()); } void duplicateExpressionLoop() { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 60f3a0376..426ad475e 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -5359,6 +5359,14 @@ private: " if (received[sig]) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("void increment(int& i) { ++i; }\n" // #6475 + "int f() {\n" + " int n;\n" + " increment(n);\n" + " return n;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Uninitialized variable: i\n", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value