Skip to content

Commit 042da30

Browse files
authored
Fix #13701 (dumpfile: move <library> element) (#7376)
1 parent 72dc99a commit 042da30

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/cppcheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static void createDumpFile(const Settings& settings,
400400
<< " pointer_bit=\"" << (settings.platform.sizeof_pointer * settings.platform.char_bit) << '\"'
401401
<< " wchar_t_bit=\"" << (settings.platform.sizeof_wchar_t * settings.platform.char_bit) << '\"'
402402
<< " size_t_bit=\"" << (settings.platform.sizeof_size_t * settings.platform.char_bit) << '\"'
403-
<< "/>" << '\n';
403+
<< "/>\n";
404404
}
405405

406406
static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand)
@@ -736,6 +736,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
736736
std::string dumpFile;
737737
createDumpFile(mSettings, file, fdump, dumpFile);
738738
if (fdump.is_open()) {
739+
fdump << getLibraryDumpData();
739740
// TODO: use tinyxml2 to create XML
740741
fdump << "<dump cfg=\"\">\n";
741742
for (const ErrorMessage& errmsg: compilerWarnings)
@@ -744,7 +745,6 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
744745
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>\n";
745746
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>\n";
746747
fdump << " </standards>\n";
747-
fdump << getLibraryDumpData();
748748
tokenizer.dump(fdump);
749749
fdump << "</dump>\n";
750750
fdump << "</dumps>\n";
@@ -1065,6 +1065,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10651065
std::string dumpFile;
10661066
createDumpFile(mSettings, file, fdump, dumpFile);
10671067
if (fdump.is_open()) {
1068+
fdump << getLibraryDumpData();
10681069
fdump << dumpProlog;
10691070
if (!mSettings.dump)
10701071
filesDeleter.addFile(dumpFile);

test/cli/dumpfile_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# python -m pytest dumpfile_test.py
3+
4+
import os
5+
6+
from testutils import cppcheck
7+
8+
9+
def test_libraries(tmpdir): #13701
10+
test_file = str(tmpdir / 'test.c')
11+
with open(test_file, 'wt') as f:
12+
f.write('x=1;\n')
13+
14+
args = ['--library=posix', '--dump', test_file]
15+
_, _, _ = cppcheck(args)
16+
17+
dumpfile = test_file + '.dump'
18+
assert os.path.isfile(dumpfile)
19+
with open(dumpfile, 'rt') as f:
20+
dump = f.read()
21+
assert '<library lib="posix"/>' in dump
22+
assert dump.find('<library lib="posix"/>') < dump.find('<dump cfg=')

0 commit comments

Comments
 (0)