Skip to content

Commit

Permalink
fixed #13391 - fixed missing file0 in cached XML results
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jan 2, 2025
1 parent e406b37 commit f331c22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
3 changes: 3 additions & 0 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
const char *attr = errmsg->Attribute("id");
id = attr ? attr : unknown;

attr = errmsg->Attribute("file0");
file0 = attr ? attr : "";

attr = errmsg->Attribute("severity");
severity = attr ? severityFromString(attr) : Severity::none;

Expand Down
50 changes: 21 additions & 29 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,11 +2675,7 @@ def test_duplicate_suppressions_mixed(tmp_path):
assert stderr == ''


@pytest.mark.xfail(strict=True)
def test_xml_builddir(tmp_path): # #13391 / #13485
build_dir = tmp_path / 'b1'
os.mkdir(build_dir)

def test_xml_output(tmp_path): # #13391 / #13485
test_file = tmp_path / 'test.cpp'
with open(test_file, 'wt') as f:
f.write("""
Expand All @@ -2690,46 +2686,42 @@ def test_xml_builddir(tmp_path): # #13391 / #13485
}
""")

_, version_str, _ = cppcheck(['--version'])
version_str = version_str.replace('Cppcheck ', '').strip()

args = [
'-q',
'--enable=style',
'--cppcheck-build-dir={}'.format(build_dir),
'--xml',
str(test_file)
]
exitcode_1, stdout_1, stderr_1 = cppcheck(args)
assert exitcode_1 == 0, stdout_1
assert stdout_1 == ''
# TODO: handle version
assert (stderr_1 ==
'''<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="2.17 dev"/>
<errors>
<error id="nullPointerRedundantCheck" severity="warning" msg="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." verbose="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." cwe="476" file0="{}" remark="boom">
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
<symbol>p</symbol>
</error>
</errors>
</results>
'''.format(test_file, test_file, test_file))

exitcode_2, stdout_2, stderr_2 = cppcheck(args)
assert exitcode_1 == exitcode_2, stdout_2
assert stdout_1 == stdout_2
assert stderr_1 == stderr_2
'''<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="{}"/>
<errors>
<error id="nullPointerRedundantCheck" severity="warning" msg="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." verbose="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." cwe="476" file0="{}" remark="boom">
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
<symbol>p</symbol>
</error>
</errors>
</results>
'''.format(version_str, str(test_file).replace('\\', '/'), test_file, test_file)) # TODO: the slashes are inconsistent


def test_internal_error_loc_int(tmp_path):
test_file = tmp_path / 'test.c'
with open(test_file, 'wt') as f:
f.write(
"""
void f() {
int i = 0x10000000000000000;
}
""")
"""
void f() {
int i = 0x10000000000000000;
}
""")

args = [
'-q',
Expand Down

0 comments on commit f331c22

Please sign in to comment.