diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 88bde9320..15fae01f9 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -5250,6 +5250,16 @@ private: " g(a);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + ctu("const int a[1] = { 1 };\n" // #11042 + "void g(const int* d) {\n" + " (void)d[2];\n" + "}\n" + "void f() {\n" + " g(a);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8.\n", + errout.str()); } void ctu_variable() { diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 69205242f..4e9b95915 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3213,8 +3213,8 @@ private: tok(code)); } - void simplifyTypedef140() { // #10798 - { + void simplifyTypedef140() { + { // #10798 const char code[] = "typedef void (*b)();\n" "enum class E { a, b, c };\n"; ASSERT_EQUALS("enum class E { a , b , c } ;", tok(code)); @@ -3224,6 +3224,11 @@ private: "enum class E { A };\n"; ASSERT_EQUALS("enum class E { A } ;", tok(code)); } + { // #11494 + const char code[] = "typedef struct S {} KEY;\n" + "class C { enum E { KEY }; };\n"; + ASSERT_EQUALS("struct S { } ; class C { enum E { KEY } ; } ;", tok(code)); + } } void simplifyTypedef141() { // #10144 diff --git a/test/teststl.cpp b/test/teststl.cpp index 8b88ef26e..a62c7af06 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4750,6 +4750,15 @@ private: " return true;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #6925 + check("void f(const std::string& s, std::string::iterator i) {\n" + " if (i != s.end() && *(i + 1) == *i) {\n" + " if (i + 1 != s.end()) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", + errout.str()); } void dereferenceInvalidIterator2() {