diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 90f0dd349..4f24025b5 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -234,8 +234,6 @@ private: TEST_CASE(negativeMemoryAllocationSizeError) // #389 TEST_CASE(negativeArraySize); - - TEST_CASE(garbage1) // #6303 } @@ -3806,14 +3804,6 @@ private: "int c[x?y:-1];\n"); ASSERT_EQUALS("", errout.str()); } - - void garbage1() { - check("void foo() {\n" - "char *a = malloc(10);\n" - "a[0]\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } }; REGISTER_TEST(TestBufferOverrun) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index b616056a0..99adeacb1 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -158,6 +158,11 @@ private: TEST_CASE(garbageCode116); // #5356 TEST_CASE(garbageCode117); // #6121 TEST_CASE(garbageCode118); // #5600 + TEST_CASE(garbageCode119); // #5598 + TEST_CASE(garbageCode120); // #4927 + TEST_CASE(garbageCode121); // #2585 + TEST_CASE(garbageCode122); // #6303 + TEST_CASE(garbageCode123); TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -165,9 +170,11 @@ private: TEST_CASE(templateSimplifierCrashes); } - std::string checkCode(const char code[], const std::string& filename = "test.cpp") { + std::string checkCode(const char code[], bool cpp = true) { // double the tests - run each example as C as well as C++ - const std::string alternatefilename = (filename=="test.c") ? "test.cpp" : "test.c"; + const char* filename = cpp ? "test.cpp" : "test.c"; + const char* alternatefilename = cpp ? "test.c" : "test.cpp"; + // run alternate check first. It should only ensure stability try { checkCodeInternal(code, alternatefilename); @@ -177,7 +184,7 @@ private: return checkCodeInternal(code, filename); } - std::string checkCodeInternal(const char code[], const std::string& filename) { + std::string checkCodeInternal(const char code[], const char* filename) { errout.str(""); Settings settings; @@ -192,7 +199,7 @@ private: // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename.c_str()); + tokenizer.tokenize(istr, filename); // call all "runChecks" in all registered Check classes for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { @@ -281,10 +288,11 @@ private: // #3585 const char code[] = "class x y { };"; + Settings settings; + settings.addEnabled("information"); + { errout.str(""); - Settings settings; - settings.addEnabled("information"); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.c"); @@ -293,8 +301,6 @@ private: } { errout.str(""); - Settings settings; - settings.addEnabled("information"); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -668,7 +674,7 @@ private: } void garbageCode67() { // #6744 - checkCode("&g[0]; { (g[0] 0) } =", "test.c"); + checkCode("&g[0]; { (g[0] 0) } =", false); } void garbageCode68() { // #6745 @@ -700,7 +706,7 @@ private: } void garbageCode75() { // #6753 - checkCode("{ { void foo() { struct }; { }; } }; struct S { } f =", "test.c"); + checkCode("{ { void foo() { struct }; { }; } }; struct S { } f =", false); } void garbageCode76() { // #6754 @@ -772,7 +778,7 @@ private: } void garbageCode93() { // #6800 - checkCode(" namespace A { } class A{ { }} class A : T ;", "test.c"); // do not crash + checkCode(" namespace A { } class A{ { }} class A : T ;", false); // do not crash } void garbageCode94() { // #6803 @@ -894,6 +900,39 @@ private: "}"), InternalError); } + void garbageCode119() { // #5598 + checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); + } + + void garbageCode120() { // #4927 + checkCode("int main() {\n" + " return 0\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + + void garbageCode121() { // #2585 + checkCode("abcdef?""?<" + "123456?""?>" + "+?""?="); + ASSERT_EQUALS("", errout.str()); + } + + void garbageCode122() { // #6303 + checkCode("void foo() {\n" + "char *a = malloc(10);\n" + "a[0]\n" + "}"); + } + + void garbageCode123() { + checkCode("namespace pr16989 {\n" + " class C {\n" + " C tpl_mem(T *) { return }\n" + " };\n" + "}"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" @@ -939,7 +978,7 @@ private: } void templateSimplifierCrashes() { - checkCode( //5950 + checkCode( // #5950 "struct A { \n" " template operator T*();\n" "}; \n" @@ -961,7 +1000,7 @@ private: " }\n" "}\n"); - checkCode( // 6034 + checkCode( // #6034 "template class T, typename... Args>\n" "struct foo > {\n" " const bool value = true;\n" @@ -976,9 +1015,9 @@ private: "}\n" ); - checkCode(" > template < . > struct Y < T > { = } ;\n"); //6108 + checkCode(" > template < . > struct Y < T > { = } ;\n"); // #6108 - checkCode( // 6117 + checkCode( // #6117 "template struct something_like_tuple\n" "{};\n" "template struct is_last {\n" @@ -997,7 +1036,7 @@ private: "SA ((is_last::value == false));\n" ); - checkCode( //6225 + checkCode( // #6225 "template \n" "void templ_fun_with_ty_pack() {}\n" " \n" @@ -1007,6 +1046,17 @@ private: " using AliasA = A;\n" "}\n" ); + + // #3449 + ASSERT_EQUALS("template < typename T > struct A ;\n" + "struct B { template < typename T > struct C } ;\n" + "{ } ;", + checkCode("template struct A;\n" + "struct B { template struct C };\n" + "{};")); + + // #4169 + checkCode("volatile true , test < test < #ifdef __ppc__ true ,"); } }; diff --git a/test/testother.cpp b/test/testother.cpp index f47b880b7..5adb8af20 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3186,13 +3186,6 @@ private: " per_state_info() : enter(0), exit(0), events(0) {}\n" "};", nullptr, false, false, false); ASSERT_EQUALS("", errout.str()); - - // Garbage code - don't crash - check("namespace pr16989 {\n" - " class C {\n" - " C tpl_mem(T *) { return }\n" - " };\n" - "}"); } @@ -3815,12 +3808,6 @@ private: "}"); ASSERT_EQUALS("", errout.str()); - // Ticket #2585 - segmentation fault for invalid code - check("abcdef?""?<" - "123456?""?>" - "+?""?="); - ASSERT_EQUALS("", errout.str()); - check("void f(char c) {\n" " printf(\"%i\", 1 + 1 ? 1 : 2);\n" // "1+1" is simplified away "}",0,false,false,false); @@ -6054,12 +6041,6 @@ private: "}", nullptr, true, false, false); ASSERT_EQUALS("", errout.str()); - // ticket #4927 Segfault in CheckOther::checkCommaSeparatedReturn() on invalid code - check("int main() {\n" - " return 0\n" - "}", nullptr, true, false, false); - ASSERT_EQUALS("", errout.str()); - // #4943 take care of C++11 initializer lists check("std::vector Bar() {\n" " return\n" diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 291b26c07..9eae5e2bf 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -59,7 +59,6 @@ private: TEST_CASE(template26); // #2721 - passing 'char[2]' as template parameter TEST_CASE(template27); // #3350 - removing unused template in macro call TEST_CASE(template28); - TEST_CASE(template29); // #3449 - don't crash for garbage code TEST_CASE(template30); // #3529 - template < template < .. TEST_CASE(template31); // #4010 - reference type TEST_CASE(template32); // #3818 - mismatching template not handled well @@ -95,7 +94,6 @@ private: // Test TemplateSimplifier::templateParameters TEST_CASE(templateParameters); - TEST_CASE(templateParameters1); // #4169 - segmentation fault TEST_CASE(templateNamePosition); } @@ -659,14 +657,6 @@ private: ASSERT_EQUALS("Fred> x ; class Fred { } ; class Fred> { } ;", tok(code)); } - void template29() { - // #3449 - garbage code (don't segfault) - const char code[] = "template struct A;\n" - "struct B { template struct C };\n" - "{};"; - ASSERT_EQUALS("template < typename T > struct A ; struct B { template < typename T > struct C } ; { } ;", tok(code)); - } - void template30() { // #3529 - template < template < .. const char code[] = "template class A, class B> void f(){}"; @@ -1216,13 +1206,6 @@ private: TODO_ASSERT_EQUALS(2U, 0U, templateParameters(" x;")); // Mishandled valid syntax } - void templateParameters1() { - // #4169 - segmentation fault (invalid code) - const char code[] = "volatile true , test < test < #ifdef __ppc__ true ,"; - // do not crash on invalid code - ASSERT_EQUALS(0, templateParameters(code)); - } - // Helper function to unit test TemplateSimplifier::getTemplateNamePosition int templateNamePositionHelper(const char code[], unsigned offset = 0) { Settings settings; diff --git a/test/teststl.cpp b/test/teststl.cpp index b2b7a0208..c263f2515 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -45,7 +45,6 @@ private: TEST_CASE(iterator11); TEST_CASE(iterator12); TEST_CASE(iterator13); - TEST_CASE(iterator14); // #5598 invalid code causing a crash TEST_CASE(dereference); TEST_CASE(dereference_break); // #3644 - handle "break" @@ -454,11 +453,6 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator14() { - check(" { { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); - ASSERT_EQUALS("", errout.str()); - } - // Dereferencing invalid pointer void dereference() { check("void f()\n"