Skip to content

Commit c37c987

Browse files
authored
fixed #13432 - do not generate (incomplete) dump files with --check-config (#7108)
1 parent 88d2e31 commit c37c987

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

lib/cppcheck.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,18 +1011,6 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10111011
}
10121012
}
10131013

1014-
FilesDeleter filesDeleter;
1015-
1016-
// write dump file xml prolog
1017-
std::ofstream fdump;
1018-
std::string dumpFile;
1019-
createDumpFile(mSettings, file, fdump, dumpFile);
1020-
if (fdump.is_open()) {
1021-
fdump << dumpProlog;
1022-
if (!mSettings.dump)
1023-
filesDeleter.addFile(dumpFile);
1024-
}
1025-
10261014
// Get directives
10271015
std::list<Directive> directives = preprocessor.createDirectives(tokens1);
10281016
preprocessor.simplifyPragmaAsm(tokens1);
@@ -1072,6 +1060,18 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10721060
}
10731061
}
10741062

1063+
FilesDeleter filesDeleter;
1064+
1065+
// write dump file xml prolog
1066+
std::ofstream fdump;
1067+
std::string dumpFile;
1068+
createDumpFile(mSettings, file, fdump, dumpFile);
1069+
if (fdump.is_open()) {
1070+
fdump << dumpProlog;
1071+
if (!mSettings.dump)
1072+
filesDeleter.addFile(dumpFile);
1073+
}
1074+
10751075
std::set<unsigned long long> hashes;
10761076
int checkCount = 0;
10771077
bool hasValidConfig = false;
@@ -1238,6 +1238,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
12381238
mErrorLogger.reportErr(errmsg);
12391239
}
12401240

1241+
// TODO: will not be closed if we encountered an exception
12411242
// dumped all configs, close root </dumps> element now
12421243
if (fdump.is_open()) {
12431244
fdump << "</dumps>" << std::endl;

test/cli/other_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,4 +2465,27 @@ def test_undef_src(tmp_path): # #13340
24652465
]
24662466
assert stderr.splitlines() == [
24672467
'{}:7:16: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file)
2468-
]
2468+
]
2469+
2470+
2471+
def test_dump_check_config(tmp_path): # #13432
2472+
test_file = tmp_path / 'test.c'
2473+
with open(test_file, 'wt') as f:
2474+
f.write("""
2475+
void f() {}
2476+
""")
2477+
2478+
args = [
2479+
'-q',
2480+
'--template=simple',
2481+
'--dump',
2482+
'--check-config',
2483+
str(test_file)
2484+
]
2485+
exitcode, stdout, stderr = cppcheck(args)
2486+
assert exitcode == 0, stdout
2487+
assert stdout == ''
2488+
assert stderr == ''
2489+
2490+
# no dump file should have been generated
2491+
assert not os.path.exists(str(test_file) + '.dump')

0 commit comments

Comments
 (0)