Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ctu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const
out << ">\n";
for (const ErrorMessage::FileLocation &loc : callValuePath)
out << " <path"
<< " " << ATTR_LOC_FILENAME << "=\"" << ErrorLogger::toxml(loc.getfile()) << "\""
<< " " << ATTR_LOC_FILENAME << "=\"" << ErrorLogger::toxml(loc.getfile(false)) << "\""
<< " " << ATTR_LOC_LINENR << "=\"" << loc.line << "\""
<< " " << ATTR_LOC_COLUMN << "=\"" << loc.column << "\""
<< " " << ATTR_INFO << "=\"" << ErrorLogger::toxml(loc.getinfo()) << "\"/>\n";
Expand Down
38 changes: 38 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4234,3 +4234,41 @@ def run_and_assert_cppcheck(stdout_exp):
# TODO:
# - invalid error
# - internalError


def test_ctu_function_call_path_slash(tmp_path): # #14591
test_file = tmp_path / 'test.cpp'
with open(test_file, "w") as f:
f.write(
"""void g(T* p)
{
*p = 0;
}

void f(T* p)
{
p = nullptr;
g(p);
}
""")

build_dir = tmp_path / 'b1'
os.makedirs(build_dir)

args = [
'-q',
'--template=simple',
'--cppcheck-build-dir={}'.format(build_dir),
str(test_file)
]

exitcode, _, _ = cppcheck(args)
assert exitcode == 0

test_a1_file = build_dir / 'test.a1'
analyzerinfo = ElementTree.fromstring(test_a1_file.read_text())
function_call_paths = analyzerinfo.findall('FileInfo/function-call/path')
assert len(function_call_paths) == 1
file = function_call_paths[0].attrib['file']
assert file
assert not '\\' in file # the path was incorrectly converted to native