Skip to content

Commit d6ac48f

Browse files
authored
fixed #14591 - store CTU function call information path with proper slashes (#8328)
1 parent 4f31d0a commit d6ac48f

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

lib/ctu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const
112112
out << ">\n";
113113
for (const ErrorMessage::FileLocation &loc : callValuePath)
114114
out << " <path"
115-
<< " " << ATTR_LOC_FILENAME << "=\"" << ErrorLogger::toxml(loc.getfile()) << "\""
115+
<< " " << ATTR_LOC_FILENAME << "=\"" << ErrorLogger::toxml(loc.getfile(false)) << "\""
116116
<< " " << ATTR_LOC_LINENR << "=\"" << loc.line << "\""
117117
<< " " << ATTR_LOC_COLUMN << "=\"" << loc.column << "\""
118118
<< " " << ATTR_INFO << "=\"" << ErrorLogger::toxml(loc.getinfo()) << "\"/>\n";

test/cli/other_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,3 +4234,41 @@ def run_and_assert_cppcheck(stdout_exp):
42344234
# TODO:
42354235
# - invalid error
42364236
# - internalError
4237+
4238+
4239+
def test_ctu_function_call_path_slash(tmp_path): # #14591
4240+
test_file = tmp_path / 'test.cpp'
4241+
with open(test_file, "w") as f:
4242+
f.write(
4243+
"""void g(T* p)
4244+
{
4245+
*p = 0;
4246+
}
4247+
4248+
void f(T* p)
4249+
{
4250+
p = nullptr;
4251+
g(p);
4252+
}
4253+
""")
4254+
4255+
build_dir = tmp_path / 'b1'
4256+
os.makedirs(build_dir)
4257+
4258+
args = [
4259+
'-q',
4260+
'--template=simple',
4261+
'--cppcheck-build-dir={}'.format(build_dir),
4262+
str(test_file)
4263+
]
4264+
4265+
exitcode, _, _ = cppcheck(args)
4266+
assert exitcode == 0
4267+
4268+
test_a1_file = build_dir / 'test.a1'
4269+
analyzerinfo = ElementTree.fromstring(test_a1_file.read_text())
4270+
function_call_paths = analyzerinfo.findall('FileInfo/function-call/path')
4271+
assert len(function_call_paths) == 1
4272+
file = function_call_paths[0].attrib['file']
4273+
assert file
4274+
assert not '\\' in file # the path was incorrectly converted to native

0 commit comments

Comments
 (0)