2323#include " testsuite.h"
2424#include " tokenize.h"
2525
26+ #include < simplecpp.h>
27+ #include < vector>
2628
2729class TestLeakAutoVar : public TestFixture {
2830public:
@@ -163,6 +165,8 @@ class TestLeakAutoVar : public TestFixture {
163165 TEST_CASE (inlineFunction); // #3989
164166
165167 TEST_CASE (smartPtrInContainer); // #8262
168+
169+ TEST_CASE (recursiveCountLimit); // #5872 #6157 #9097
166170 }
167171
168172 void check (const char code[], bool cpp = false ) {
@@ -181,6 +185,32 @@ class TestLeakAutoVar : public TestFixture {
181185 c.runChecks (&tokenizer, &settings, this );
182186 }
183187
188+ void checkP (const char code[], bool cpp = false ) {
189+ // Clear the error buffer..
190+ errout.str (" " );
191+
192+ // Raw tokens..
193+ std::vector<std::string> files (1 , cpp?" test.cpp" :" test.c" );
194+ std::istringstream istr (code);
195+ const simplecpp::TokenList tokens1 (istr, files, files[0 ]);
196+
197+ // Preprocess..
198+ simplecpp::TokenList tokens2 (files);
199+ std::map<std::string, simplecpp::TokenList*> filedata;
200+ simplecpp::preprocess (tokens2, tokens1, files, filedata, simplecpp::DUI ());
201+
202+ // Tokenizer..
203+ Tokenizer tokenizer (&settings, this );
204+ tokenizer.createTokens (&tokens2);
205+ tokenizer.simplifyTokens1 (" " );
206+
207+ // Check for leaks..
208+ CheckLeakAutoVar c;
209+ settings.checkLibrary = true ;
210+ settings.addEnabled (" information" );
211+ c.runChecks (&tokenizer, &settings, this );
212+ }
213+
184214 void assign1 () {
185215 check (" void f() {\n "
186216 " char *p = malloc(10);\n "
@@ -1776,6 +1806,17 @@ class TestLeakAutoVar : public TestFixture {
17761806 ASSERT_EQUALS (" " , errout.str ());
17771807 }
17781808
1809+ void recursiveCountLimit () { // #5872 #6157 #9097
1810+ ASSERT_THROW (checkP (" #define ONE else if (0) { }\n "
1811+ " #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n "
1812+ " #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n "
1813+ " #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n "
1814+ " void foo() {\n "
1815+ " if (0) { }\n "
1816+ " THOU\n "
1817+ " }" ), InternalError);
1818+ }
1819+
17791820};
17801821
17811822REGISTER_TEST (TestLeakAutoVar)
0 commit comments