Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #11883 - CTU path information from build dir was not being used #7202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -212,7 +212,7 @@ bool CTU::FileInfo::FunctionCall::loadFromXml(const tinyxml2::XMLElement *xmlEle
const int line = readAttrInt(e2, ATTR_LOC_LINENR, &error);
const int column = readAttrInt(e2, ATTR_LOC_COLUMN, &error);
ErrorMessage::FileLocation loc(file, std::move(info), line, column);
(void)loc; // TODO: loc is unused
callValuePath.emplace_back(std::move(loc));
}
return !error;
}
Expand Down
52 changes: 51 additions & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2784,4 +2784,54 @@ def test_addon_suppr_cli_file_line(tmp_path):

def test_addon_suppr_cli_absfile_line(tmp_path):
test_file = tmp_path / 'test.c'
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:{}:3'.format(test_file)])
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:{}:3'.format(test_file)])


def test_ctu_path_builddir(tmp_path): # #11883
build_dir = tmp_path / 'b1'
os.mkdir(build_dir)

test_file = tmp_path / 'test.c'
with open(test_file, 'wt') as f:
f.write("""
void f(int *p) { *p = 3; }
int main() {
int *p = 0;
f(p);
}
""")

args = [
'-q',
'--enable=style',
'--suppress=nullPointer', # we only care about the CTU findings
'--cppcheck-build-dir={}'.format(build_dir),
str(test_file)
]

# the CTU path was not properly read leading to missing location information
stderr_exp = [
'{}:2:19: error: Null pointer dereference: p [ctunullpointer]'.format(test_file),
'void f(int *p) { *p = 3; }',
' ^',
"{}:4:14: note: Assignment 'p=0', assigned value is 0".format(test_file),
' int *p = 0;',
' ^',
'{}:5:2: note: Calling function f, 1st argument is null'.format(test_file),
'f(p);',
' ^',
'{}:2:19: note: Dereferencing argument p that is null'.format(test_file),
'void f(int *p) { *p = 3; }',
' ^'
]

exitcode_1, stdout_1, stderr_1 = cppcheck(args)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho this print should be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - an accidental leftover. Will be removed in the follow-up.

print(stderr_1)
assert exitcode_1 == 0, stdout_1
assert stdout_1 == ''
assert stderr_1.splitlines() == stderr_exp

exitcode_2, stdout_2, stderr_2 = cppcheck(args)
assert exitcode_2 == 0, stdout_2
assert stdout_2 == ''
assert stderr_2.splitlines() == stderr_exp
Loading