@@ -430,3 +430,51 @@ def test_nullpointer_out_of_memory(tmpdir, single_file):
430430 else :
431431 # the bug is found using ctu analysis
432432 assert results == ['[ctunullpointerOutOfMemory]' ]
433+
434+
435+ def __test_nullpointer_nested_call (tmpdir , extra_args ):
436+ with open (tmpdir / 'header.h' , 'wt' ) as f :
437+ f .write ('void wrapper(int *p);\n ' )
438+ with open (tmpdir / 'test1.c' , 'wt' ) as f :
439+ f .write ('#include "header.h"\n '
440+ 'int g;\n '
441+ 'void deref(int *p) { g = *p; }\n '
442+ 'void wrapper(int *p) { deref(p); }\n ' )
443+ with open (tmpdir / 'test2.c' , 'wt' ) as f :
444+ f .write ('#include "header.h"\n '
445+ 'void f(void) { wrapper(0); }\n ' )
446+
447+ args = [
448+ '-q' ,
449+ '--template=simple' ,
450+ '--error-exitcode=1' ,
451+ 'test1.c' ,
452+ 'test2.c'
453+ ]
454+
455+ args += extra_args
456+
457+ ret , stdout , stderr = cppcheck (args , cwd = tmpdir )
458+ lines = stderr .splitlines ()
459+ assert lines == [
460+ 'test1.c:3:27: error: Null pointer dereference: p [ctunullpointer]'
461+ ]
462+ assert stdout == ''
463+ assert ret == 1 , stdout
464+
465+
466+ def test_nullpointer_nested_call (tmpdir ):
467+ __test_nullpointer_nested_call (tmpdir , ['-j1' ])
468+
469+
470+ def test_nullpointer_nested_call_builddir_cached (tmpdir ):
471+ build_dir = os .path .join (tmpdir , 'b1' )
472+ os .mkdir (build_dir )
473+ __test_nullpointer_nested_call (tmpdir , ['-j1' , '--cppcheck-build-dir={}' .format (build_dir )])
474+ __test_nullpointer_nested_call (tmpdir , ['-j1' , '--cppcheck-build-dir={}' .format (build_dir )])
475+
476+
477+ def test_nullpointer_nested_call_builddir_j (tmpdir ):
478+ build_dir = os .path .join (tmpdir , 'b1' )
479+ os .mkdir (build_dir )
480+ __test_nullpointer_nested_call (tmpdir , ['-j2' , '--cppcheck-build-dir={}' .format (build_dir )])
0 commit comments