Skip to content

Commit 48cc356

Browse files
authored
fixed #11883 - CTU path information from build dir was not being used (#7202)
1 parent 0f754d1 commit 48cc356

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/ctu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ bool CTU::FileInfo::FunctionCall::loadFromXml(const tinyxml2::XMLElement *xmlEle
212212
const int line = readAttrInt(e2, ATTR_LOC_LINENR, &error);
213213
const int column = readAttrInt(e2, ATTR_LOC_COLUMN, &error);
214214
ErrorMessage::FileLocation loc(file, std::move(info), line, column);
215-
(void)loc; // TODO: loc is unused
215+
callValuePath.emplace_back(std::move(loc));
216216
}
217217
return !error;
218218
}

test/cli/other_test.py

+51-1
Original file line numberDiff line numberDiff line change
@@ -2784,4 +2784,54 @@ def test_addon_suppr_cli_file_line(tmp_path):
27842784

27852785
def test_addon_suppr_cli_absfile_line(tmp_path):
27862786
test_file = tmp_path / 'test.c'
2787-
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:{}:3'.format(test_file)])
2787+
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:{}:3'.format(test_file)])
2788+
2789+
2790+
def test_ctu_path_builddir(tmp_path): # #11883
2791+
build_dir = tmp_path / 'b1'
2792+
os.mkdir(build_dir)
2793+
2794+
test_file = tmp_path / 'test.c'
2795+
with open(test_file, 'wt') as f:
2796+
f.write("""
2797+
void f(int *p) { *p = 3; }
2798+
int main() {
2799+
int *p = 0;
2800+
f(p);
2801+
}
2802+
""")
2803+
2804+
args = [
2805+
'-q',
2806+
'--enable=style',
2807+
'--suppress=nullPointer', # we only care about the CTU findings
2808+
'--cppcheck-build-dir={}'.format(build_dir),
2809+
str(test_file)
2810+
]
2811+
2812+
# the CTU path was not properly read leading to missing location information
2813+
stderr_exp = [
2814+
'{}:2:19: error: Null pointer dereference: p [ctunullpointer]'.format(test_file),
2815+
'void f(int *p) { *p = 3; }',
2816+
' ^',
2817+
"{}:4:14: note: Assignment 'p=0', assigned value is 0".format(test_file),
2818+
' int *p = 0;',
2819+
' ^',
2820+
'{}:5:2: note: Calling function f, 1st argument is null'.format(test_file),
2821+
'f(p);',
2822+
' ^',
2823+
'{}:2:19: note: Dereferencing argument p that is null'.format(test_file),
2824+
'void f(int *p) { *p = 3; }',
2825+
' ^'
2826+
]
2827+
2828+
exitcode_1, stdout_1, stderr_1 = cppcheck(args)
2829+
print(stderr_1)
2830+
assert exitcode_1 == 0, stdout_1
2831+
assert stdout_1 == ''
2832+
assert stderr_1.splitlines() == stderr_exp
2833+
2834+
exitcode_2, stdout_2, stderr_2 = cppcheck(args)
2835+
assert exitcode_2 == 0, stdout_2
2836+
assert stdout_2 == ''
2837+
assert stderr_2.splitlines() == stderr_exp

0 commit comments

Comments
 (0)