From f6a2034a4c9a38699b6d41023c1f009b9762ad0f Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Tue, 19 Nov 2019 21:50:53 +0100 Subject: [PATCH] Add regression tests for fixed crashes (#2379) The invalid code in Trac tickets #8750, #8753, #8756, #8762, #8764 and #8765 previously crashed cppcheck. Now it throws a syntax error instead. Add some tests for these tickets. --- test/testgarbage.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 4ce772b7e..c23788654 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -238,6 +238,12 @@ private: TEST_CASE(garbageCode204); TEST_CASE(garbageCode205); TEST_CASE(garbageCode206); + TEST_CASE(garbageCode207); // #8750 + TEST_CASE(garbageCode208); // #8753 + TEST_CASE(garbageCode209); // #8756 + TEST_CASE(garbageCode210); // #8762 + TEST_CASE(garbageCode211); // #8764 + TEST_CASE(garbageCode212); // #8765 TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1631,6 +1637,30 @@ private: ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (a operator== :) }")); } + void garbageCode207() { // #8750 + ASSERT_THROW(checkCode("d f(){(.n00e0(return%n00e0''('')));}"), InternalError); + } + + void garbageCode208() { // #8753 + ASSERT_THROW(checkCode("d f(){(for(((((0{t b;((((((((()))))))))}))))))}"), InternalError); + } + + void garbageCode209() { // #8756 + ASSERT_THROW(checkCode("{(- -##0xf/-1 0)[]}"), InternalError); + } + + void garbageCode210() { // #8762 + ASSERT_THROW(checkCode("{typedef typedef c n00e0[]c000(;n00e0&c000)}"), InternalError); + } + + void garbageCode211() { // #8764 + ASSERT_THROW(checkCode("{typedef f typedef[]({typedef e e,>;typedef(((typedef (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858