diff --git a/test/cli/other_test.py b/test/cli/other_test.py index bd7030d88bd..cc509035e94 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -2085,7 +2085,7 @@ def test_def_undef(tmp_path): void f() { #ifndef DEF_1 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif } """) @@ -2103,7 +2103,7 @@ def test_def_undef(tmp_path): 'Checking {}: DEF_1=1...'.format(test_file) # TODO: should not print DEF_1 - see #13335 ] assert stderr.splitlines() == [ - '{}:5:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:5:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] @@ -2115,10 +2115,10 @@ def test_def_def(tmp_path): # #13334 void f() { #if DEF_1 == 3 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif #if DEF_1 == 7 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif } """) @@ -2136,7 +2136,7 @@ def test_def_def(tmp_path): # #13334 'Checking {}: DEF_1=3;DEF_1=7...'.format(test_file) # TODO: should not print DEF_1 twice - see #13335 ] assert stderr.splitlines() == [ - '{}:8:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:8:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] @@ -2148,7 +2148,7 @@ def test_def_undef_def(tmp_path): # #13334 void f() { #ifdef DEF_1 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif } """) @@ -2167,7 +2167,7 @@ def test_def_undef_def(tmp_path): # #13334 'Checking {}: DEF_1=1;DEF_1=1...'.format(test_file) # TODO: should not print DEF_1 twice - see #13335 ] assert stderr.splitlines() == [ - '{}:5:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:5:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] @@ -2178,7 +2178,7 @@ def test_undef(tmp_path): void f() { #ifndef DEF_1 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif } """) @@ -2194,7 +2194,7 @@ def test_undef(tmp_path): 'Checking {} ...'.format(test_file) ] assert stderr.splitlines() == [ - '{}:5:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:5:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] @@ -2208,7 +2208,7 @@ def test_undef_src(tmp_path): # #13340 void f() { #ifdef DEF_1 - {int i = *((int*)0);} + (void)(*((int*)0)); #endif } """) @@ -2224,7 +2224,7 @@ def test_undef_src(tmp_path): # #13340 'Checking {} ...'.format(test_file) ] assert stderr.splitlines() == [ - '{}:7:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:7:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] @@ -2623,7 +2623,7 @@ def test_debug(tmp_path): f.write( """void f { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -2649,7 +2649,7 @@ def test_debug_xml(tmp_path): f.write( """void f { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -2691,7 +2691,7 @@ def test_debug_verbose(tmp_path): f.write( """void f { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -2718,7 +2718,7 @@ def test_debug_verbose_xml(tmp_path): f.write( """void f { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -2764,7 +2764,7 @@ def __test_debug_template(tmp_path, verbose=False, debug=False): """template class TemplCl; void f() { - (void)*((int*)nullptr); + (void)(*((int*)nullptr)); } """) @@ -2803,7 +2803,7 @@ def __test_debug_template(tmp_path, verbose=False, debug=False): else: assert stdout.count('### Template Simplifier pass ') == 1 assert stderr.splitlines() == [ - '{}:4:13: error: Null pointer dereference: (int*)nullptr [nullPointer]'.format(test_file) + '{}:4:14: error: Null pointer dereference: (int*)nullptr [nullPointer]'.format(test_file) ] return stdout @@ -3408,7 +3408,7 @@ def __test_debug_normal(tmp_path, verbose): f.write( """void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -3436,7 +3436,7 @@ def __test_debug_normal(tmp_path, verbose): assert stdout.find('##AST') == -1 assert stdout.find('### Template Simplifier pass ') == -1 assert stderr.splitlines() == [ - '{}:3:13: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] return stdout @@ -3458,7 +3458,7 @@ def __test_debug_simplified(tmp_path, verbose): f.write( """void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -3480,7 +3480,7 @@ def __test_debug_simplified(tmp_path, verbose): assert stdout.find('##AST') == -1 assert stdout.find('### Template Simplifier pass ') == -1 assert stderr.splitlines() == [ - '{}:3:13: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] return stdout @@ -3501,7 +3501,7 @@ def __test_debug_symdb(tmp_path, verbose): f.write( """void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -3523,7 +3523,7 @@ def __test_debug_symdb(tmp_path, verbose): assert stdout.find('##AST') == -1 assert stdout.find('### Template Simplifier pass ') == -1 assert stderr.splitlines() == [ - '{}:3:13: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] return stdout @@ -3545,7 +3545,7 @@ def __test_debug_ast(tmp_path, verbose): f.write( """void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -3567,7 +3567,7 @@ def __test_debug_ast(tmp_path, verbose): assert stdout.find('##AST') != -1 assert stdout.find('### Template Simplifier pass ') == -1 assert stderr.splitlines() == [ - '{}:3:13: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] return stdout @@ -3588,7 +3588,7 @@ def __test_debug_valueflow(tmp_path, verbose): f.write( """void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) @@ -3610,7 +3610,7 @@ def __test_debug_valueflow(tmp_path, verbose): assert stdout.find('##AST') == -1 assert stdout.find('### Template Simplifier pass ') == -1 assert stderr.splitlines() == [ - '{}:3:13: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file) ] return stdout @@ -3632,7 +3632,7 @@ def test_debug_syntaxerror_c(tmp_path): template class TemplCl; void f() { - (void)*((int*)0); + (void)(*((int*)0)); } """) diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index c4b818b79b9..b15d781459e 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -170,10 +170,9 @@ class TestCppcheck : public TestFixture { { REDIRECT; ScopedFile file(fname, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); int called = 0; @@ -240,25 +239,24 @@ class TestCppcheck : public TestFixture { } void checkWithFile() const { - checkWithFileInternal("file.cpp", false); + checkWithFileInternal("file.c", false); } void checkWithFileWithTools() const { - checkWithFileInternal("file_tools.cpp", true); + checkWithFileInternal("file_tools.c", true); } void checkWithFileWithToolsNoCommand() const { - checkWithFileInternal("file_tools_nocmd.cpp", true, true); + checkWithFileInternal("file_tools_nocmd.c", true, true); } void checkWithFSInternal(const std::string& fname, bool tools, bool nocmd = false) const { REDIRECT; ScopedFile file(fname, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); int called = 0; @@ -325,27 +323,26 @@ class TestCppcheck : public TestFixture { } void checkWithFS() const { - checkWithFSInternal("fs.cpp", false); + checkWithFSInternal("fs.c", false); } void checkWithFSWithTools() const { - checkWithFSInternal("fs_tools.cpp", true); + checkWithFSInternal("fs_tools.c", true); } void checkWithFSWithToolsNoCommand() const { - checkWithFSInternal("fs_tools_nocmd.cpp", true, true); + checkWithFSInternal("fs_tools_nocmd.c", true, true); } void suppress_error_library() const { - ScopedFile file("suppr_err_lib.cpp", - "int main()\n" + ScopedFile file("suppr_err_lib.c", + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); - const char xmldata[] = R"()"; + const char xmldata[] = R"()"; const Settings s = settingsBuilder().libraryxml(xmldata).build(); Suppressions supprs; ErrorLogger2 errorLogger; @@ -364,11 +361,11 @@ class TestCppcheck : public TestFixture { ScopedFile file("inc.h", "inline void f()\n" "{\n" - " (void)*((int*)0);\n" + " (void)(*((int*)0));\n" "}"); - ScopedFile test_file_a("a.cpp", + ScopedFile test_file_a("a.c", "#include \"inc.h\""); - ScopedFile test_file_b("b.cpp", + ScopedFile test_file_b("b.c", "#include \"inc.h\""); // this is the "simple" format @@ -385,16 +382,16 @@ class TestCppcheck : public TestFixture { // the internal errorlist is cleared after each check() call ASSERT_EQUALS(2, errorLogger.errmsgs.size()); auto it = errorLogger.errmsgs.cbegin(); - ASSERT_EQUALS("a.cpp", it->file0); + ASSERT_EQUALS("a.c", it->file0); ASSERT_EQUALS("nullPointer", it->id); ++it; - ASSERT_EQUALS("b.cpp", it->file0); + ASSERT_EQUALS("b.c", it->file0); ASSERT_EQUALS("nullPointer", it->id); } void unique_errors_2() const { - ScopedFile test_file("c.cpp", + ScopedFile test_file("c.c", "void f()\n" "{\n" "const long m[9] = {};\n" @@ -416,7 +413,7 @@ class TestCppcheck : public TestFixture { // the internal errorlist is cleared after each check() call ASSERT_EQUALS(2, errorLogger.errmsgs.size()); auto it = errorLogger.errmsgs.cbegin(); - ASSERT_EQUALS("c.cpp", it->file0); + ASSERT_EQUALS("c.c", it->file0); ASSERT_EQUALS(1, it->callStack.size()); { auto stack = it->callStack.cbegin(); @@ -425,7 +422,7 @@ class TestCppcheck : public TestFixture { } ASSERT_EQUALS("arrayIndexOutOfBounds", it->id); ++it; - ASSERT_EQUALS("c.cpp", it->file0); + ASSERT_EQUALS("c.c", it->file0); ASSERT_EQUALS(1, it->callStack.size()); { auto stack = it->callStack.cbegin(); @@ -479,10 +476,10 @@ class TestCppcheck : public TestFixture { Suppressions supprs; ErrorLogger2 errorLogger; CppCheck cppcheck(s, supprs, errorLogger, false, {}); - std::vector files{"/some/path/test.cpp"}; + std::vector files{"/some/path/test.c"}; simplecpp::TokenList tokens1(files); const std::string expected = " \n" - " \n" + " \n" " \n"; ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1)); @@ -494,7 +491,7 @@ class TestCppcheck : public TestFixture { simplecpp::OutputList outputList; const simplecpp::TokenList tokens2(fin, files, "", &outputList); const std::string expected2 = " \n" - " \n" + " \n" " \n" " \n" " \n" @@ -511,7 +508,7 @@ class TestCppcheck : public TestFixture { Settings s; s.libraries.emplace_back("std.cfg"); CppCheck cppcheck(s, supprs, errorLogger, false, {}); - //std::vector files{ "/some/path/test.cpp" }; + //std::vector files{ "/some/path/test.c" }; const std::string expected = " \n"; ASSERT_EQUALS(expected, cppcheck.getLibraryDumpData()); } diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index ff404f11c66..1be70bed8a7 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -68,19 +68,19 @@ class TestProcessExecutorBase : public TestFixture { std::list filelist; if (opt.filesList.empty()) { for (int i = 1; i <= files; ++i) { - std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp"; - filelist.emplace_back(f_s, Standards::Language::CPP, data.size()); + std::string f_s = fprefix() + "_" + std::to_string(i) + ".c"; + filelist.emplace_back(f_s, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(std::move(f_s), Standards::Language::CPP, data.size()); + fileSettings.emplace_back(std::move(f_s), Standards::Language::C, data.size()); } } } else { for (const auto& f : opt.filesList) { - filelist.emplace_back(f, Standards::Language::CPP, data.size()); + filelist.emplace_back(f, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(f, Standards::Language::CPP, data.size()); + fileSettings.emplace_back(f, Standards::Language::C, data.size()); } } } @@ -136,14 +136,13 @@ class TestProcessExecutorBase : public TestFixture { void deadlock_with_many_errors() { std::ostringstream oss; - oss << "int main()\n" + oss << "void f()\n" << "{\n"; const int num_err = 1; for (int i = 0; i < num_err; i++) { - oss << " {int i = *((int*)0);}\n"; + oss << " (void)(*((int*)0));\n"; } - oss << " return 0;\n" - << "}\n"; + oss << "}\n"; const int num_files = 3; check(2, num_files, num_files, oss.str()); ASSERT_EQUALS(1LL * num_err * num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); @@ -152,10 +151,9 @@ class TestProcessExecutorBase : public TestFixture { void many_threads() { const int num_files = 100; check(16, num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS(num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); } @@ -164,10 +162,9 @@ class TestProcessExecutorBase : public TestFixture { void many_threads_showtime() { SUPPRESS; check(16, 100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them ignore_errout(); @@ -178,10 +175,9 @@ class TestProcessExecutorBase : public TestFixture { ScopedFile plistFile("dummy", "", plistOutput); check(16, 100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them ignore_errout(); @@ -213,21 +209,19 @@ class TestProcessExecutorBase : public TestFixture { void one_error_less_files() { check(2, 1, 1, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); - ASSERT_EQUALS("[" + fprefix() + "_1.cpp:3:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[" + fprefix() + "_1.c:3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } void one_error_several_files() { const int num_files = 20; check(2, num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS(num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); } @@ -290,20 +284,19 @@ class TestProcessExecutorBase : public TestFixture { dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)); const std::string output_s = GET_REDIRECT_OUTPUT; - TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_1.cpp: ") != std::string::npos); - TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_2.cpp: ") != std::string::npos); + TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_1.c: ") != std::string::npos); + TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_2.c: ") != std::string::npos); } void suppress_error_library() { SUPPRESS; const Settings settingsOld = settings; // TODO: get rid of this - const char xmldata[] = R"()"; + const char xmldata[] = R"()"; settings = settingsBuilder().libraryxml(xmldata).build(); check(2, 1, 0, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS("", errout_str()); settings = settingsOld; @@ -314,12 +307,12 @@ class TestProcessExecutorBase : public TestFixture { ScopedFile inc_h(fprefix() + ".h", "inline void f()\n" "{\n" - " (void)*((int*)0);\n" + " (void)(*((int*)0));\n" "}"); check(2, 2, 2, "#include \"" + inc_h.name() +"\""); // this is made unique by the executor - ASSERT_EQUALS("[" + inc_h.name() + ":3:11]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[" + inc_h.name() + ":3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } // TODO: test whole program analysis diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 25eb43ac4bc..281a75b5763 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -73,19 +73,19 @@ class TestSingleExecutorBase : public TestFixture { std::list filelist; if (opt.filesList.empty()) { for (int i = 1; i <= files; ++i) { - std::string f_s = fprefix() + "_" + zpad3(i) + ".cpp"; - filelist.emplace_back(f_s, Standards::Language::CPP, data.size()); + std::string f_s = fprefix() + "_" + zpad3(i) + ".c"; + filelist.emplace_back(f_s, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(std::move(f_s), Standards::Language::CPP, data.size()); + fileSettings.emplace_back(std::move(f_s), Standards::Language::C, data.size()); } } } else { for (const auto& f : opt.filesList) { - filelist.emplace_back(f, Standards::Language::CPP, data.size()); + filelist.emplace_back(f, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(f, Standards::Language::CPP, data.size()); + fileSettings.emplace_back(f, Standards::Language::C, data.size()); } } } @@ -139,16 +139,15 @@ class TestSingleExecutorBase : public TestFixture { void many_files() { const int num_files = 100; check(num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.quiet = false)); { std::string expected; for (int i = 1; i <= num_files; ++i) { - expected += "Checking " + fprefix() + "_" + zpad3(i) + ".cpp ...\n"; + expected += "Checking " + fprefix() + "_" + zpad3(i) + ".c ...\n"; expected += std::to_string(i) + "/100 files checked " + std::to_string(i) + "% done\n"; } ASSERT_EQUALS(expected, output_str()); @@ -156,7 +155,7 @@ class TestSingleExecutorBase : public TestFixture { { std::string expected; for (int i = 1; i <= num_files; ++i) { - expected += "[" + fprefix() + "_" + zpad3(i) + ".cpp:3:13]: (error) Null pointer dereference: (int*)0 [nullPointer]\n"; + expected += "[" + fprefix() + "_" + zpad3(i) + ".c:3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n"; } ASSERT_EQUALS(expected, errout_str()); } @@ -165,10 +164,9 @@ class TestSingleExecutorBase : public TestFixture { void many_files_showtime() { SUPPRESS; check(100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them ignore_errout(); @@ -179,10 +177,9 @@ class TestSingleExecutorBase : public TestFixture { ScopedFile plistFile("dummy", "", plistOutput); check(100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them ignore_errout(); @@ -214,26 +211,24 @@ class TestSingleExecutorBase : public TestFixture { void one_error_less_files() { check(1, 1, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); - ASSERT_EQUALS("[" + fprefix() + "_" + zpad3(1) + ".cpp:3:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[" + fprefix() + "_" + zpad3(1) + ".c:3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } void one_error_several_files() { const int num_files = 20; check(num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); { std::string expected; for (int i = 1; i <= num_files; ++i) { - expected += "[" + fprefix() + "_" + zpad3(i) + ".cpp:3:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n"; + expected += "[" + fprefix() + "_" + zpad3(i) + ".c:3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n"; } ASSERT_EQUALS(expected, errout_str()); } @@ -295,20 +290,19 @@ class TestSingleExecutorBase : public TestFixture { dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)); const std::string output_s = GET_REDIRECT_OUTPUT; - ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(1) + ".cpp: ") != std::string::npos); - ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(2) + ".cpp: ") != std::string::npos); + ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(1) + ".c: ") != std::string::npos); + ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(2) + ".c: ") != std::string::npos); } void suppress_error_library() { SUPPRESS; const Settings settingsOld = settings; // TODO: get rid of this - const char xmldata[] = R"()"; + const char xmldata[] = R"()"; settings = settingsBuilder().libraryxml(xmldata).build(); check(1, 0, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS("", errout_str()); settings = settingsOld; @@ -319,14 +313,14 @@ class TestSingleExecutorBase : public TestFixture { ScopedFile inc_h(fprefix() + ".h", "inline void f()\n" "{\n" - " (void)*((int*)0);\n" + " (void)(*((int*)0));\n" "}"); check(2, 2, "#include \"" + inc_h.name() + "\""); // these are not actually made unique by the implementation. That needs to be done by the given ErrorLogger ASSERT_EQUALS( - "[" + inc_h.name() + ":3:11]: (error) Null pointer dereference: (int*)0 [nullPointer]\n" - "[" + inc_h.name() + ":3:11]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", + "[" + inc_h.name() + ":3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n" + "[" + inc_h.name() + ":3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index d96e219153a..e07e51707e0 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -68,19 +68,19 @@ class TestThreadExecutorBase : public TestFixture { std::list filelist; if (opt.filesList.empty()) { for (int i = 1; i <= files; ++i) { - std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp"; - filelist.emplace_back(f_s, Standards::Language::CPP, data.size()); + std::string f_s = fprefix() + "_" + std::to_string(i) + ".c"; + filelist.emplace_back(f_s, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(std::move(f_s), Standards::Language::CPP, data.size()); + fileSettings.emplace_back(std::move(f_s), Standards::Language::C, data.size()); } } } else { for (const auto& f : opt.filesList) { - filelist.emplace_back(f, Standards::Language::CPP, data.size()); + filelist.emplace_back(f, Standards::Language::C, data.size()); if (useFS) { - fileSettings.emplace_back(f, Standards::Language::CPP, data.size()); + fileSettings.emplace_back(f, Standards::Language::C, data.size()); } } } @@ -135,14 +135,13 @@ class TestThreadExecutorBase : public TestFixture { void deadlock_with_many_errors() { std::ostringstream oss; - oss << "int main()\n" + oss << "void f()\n" << "{\n"; const int num_err = 1; for (int i = 0; i < num_err; i++) { - oss << " {int i = *((int*)0);}\n"; + oss << " (void)(*((int*)0));\n"; } - oss << " return 0;\n" - << "}\n"; + oss << "}\n"; const int num_files = 3; check(2, num_files, num_files, oss.str()); ASSERT_EQUALS(1LL * num_err * num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); @@ -151,10 +150,9 @@ class TestThreadExecutorBase : public TestFixture { void many_threads() { const int num_files = 100; check(16, num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS(num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); } @@ -163,10 +161,9 @@ class TestThreadExecutorBase : public TestFixture { void many_threads_showtime() { SUPPRESS; check(16, 100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them ignore_errout(); @@ -177,10 +174,9 @@ class TestThreadExecutorBase : public TestFixture { ScopedFile plistFile("dummy", "", plistOutput); check(16, 100, 100, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them ignore_errout(); @@ -212,21 +208,19 @@ class TestThreadExecutorBase : public TestFixture { void one_error_less_files() { check(2, 1, 1, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); - ASSERT_EQUALS("[" + fprefix() + "_1.cpp:3:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[" + fprefix() + "_1.c:3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } void one_error_several_files() { const int num_files = 20; check(2, num_files, num_files, - "int main()\n" + "void f()\n" "{\n" - " {int i = *((int*)0);}\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS(num_files, cppcheck::count_all_of(errout_str(), "(error) Null pointer dereference: (int*)0")); } @@ -289,20 +283,19 @@ class TestThreadExecutorBase : public TestFixture { dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)); const std::string output_s = GET_REDIRECT_OUTPUT; - ASSERT(output_s.find("Check time: " + fprefix() + "_1.cpp: ") != std::string::npos); - ASSERT(output_s.find("Check time: " + fprefix() + "_2.cpp: ") != std::string::npos); + ASSERT(output_s.find("Check time: " + fprefix() + "_1.c: ") != std::string::npos); + ASSERT(output_s.find("Check time: " + fprefix() + "_2.c: ") != std::string::npos); } void suppress_error_library() { SUPPRESS; const Settings settingsOld = settings; // TODO: get rid of this - const char xmldata[] = R"()"; + const char xmldata[] = R"()"; settings = settingsBuilder().libraryxml(xmldata).build(); check(2, 1, 0, - "int main()\n" + "void f()\n" "{\n" - " int i = *((int*)0);\n" - " return 0;\n" + " (void)(*((int*)0));\n" "}"); ASSERT_EQUALS("", errout_str()); settings = settingsOld; @@ -313,12 +306,12 @@ class TestThreadExecutorBase : public TestFixture { ScopedFile inc_h(fprefix() + ".h", "inline void f()\n" "{\n" - " (void)*((int*)0);\n" + " (void)(*((int*)0));\n" "}"); check(2, 2, 2, "#include \"" + inc_h.name() +"\""); // this is made unique by the executor - ASSERT_EQUALS("[" + inc_h.name() + ":3:11]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[" + inc_h.name() + ":3:12]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); } // TODO: test whole program analysis