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

refs #13543 - added test showing duplicated whole program analysis findings #7208

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
86 changes: 85 additions & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2784,4 +2784,88 @@ 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)
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


@pytest.mark.xfail(strict=True)
def test_ctu_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',
'--template=simple',
'--enable=style',
'--suppress=nullPointer', # we only care about the CTU findings
'--cppcheck-build-dir={}'.format(build_dir),
'-j1',
'--emit-duplicates',
str(test_file)
]

# the CTU was run and then evaluated again from the builddir leading to duplicated findings
exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
assert stdout == ''
assert stderr.splitlines() == [
'{}:2:19: error: Null pointer dereference: p [ctunullpointer]'.format(test_file)
]