@@ -2784,4 +2784,54 @@ def test_addon_suppr_cli_file_line(tmp_path):
2784
2784
2785
2785
def test_addon_suppr_cli_absfile_line (tmp_path ):
2786
2786
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