From 0729b8c9e384851dff283319f94acb14bfa9eaee Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 20 Apr 2026 10:51:08 +0200 Subject: [PATCH] fixed #14675 - provide proper error ID for `simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND` --- lib/preprocessor.cpp | 4 +- test/cli/other_test.py | 130 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 9528360906e..273d8df6123 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -997,8 +997,9 @@ static std::string simplecppErrToId(simplecpp::Output::Type type) return "includeNestedTooDeeply"; case simplecpp::Output::FILE_NOT_FOUND: return "missingFile"; - // should never occur case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND: + return "missingIncludeExplicit"; + // should never occur case simplecpp::Output::DUI_ERROR: // handled separately case simplecpp::Output::MISSING_HEADER: @@ -1074,6 +1075,7 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se preprocessor.error(loc, "message", simplecpp::Output::UNHANDLED_CHAR_ERROR); preprocessor.error(loc, "message", simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY); preprocessor.error(loc, "message", simplecpp::Output::FILE_NOT_FOUND); + preprocessor.error(loc, "message", simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND); preprocessor.invalidSuppression(loc, "message"); } diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 5c06bd07a94..e28a7305ce9 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -4427,3 +4427,133 @@ def test_inline_block_suppr_builddir_twice(tmp_path): assert exitcode == 0 assert stdout == '' assert stderr == '' + + +def test_dui_include(tmp_path): + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write('void f() {}') + + inc_file = tmp_path / 'inc.h' + with open(inc_file, "w") as f: + f.write( +""" +void f_i() +{ + (void)(*((int*)0)); +} +""") + + args = [ + '-q', + '--template=simple', + f'--include={inc_file}', + str(test_file) + ] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0 + assert stdout == '' + assert stderr.splitlines() == [ + f'{inc_file}:4:14: error: Null pointer dereference: (int*)0 [nullPointer]' + ] + + +def test_dui_include_missing(tmp_path): # #14675 + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write('void f() {}') + + args = [ + '-q', + '--template=simple', + '--include=missing.h', + str(test_file) + ] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0 + assert stdout == '' + assert stderr.splitlines() == [ + f"{test_file}:0:0: error: Can not open include file 'missing.h' that is explicitly included. [missingIncludeExplicit]" + ] + + +def test_dui_include_relative(tmp_path): + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write('void f() {}') + + inc_file = tmp_path / 'inc.h' + with open(inc_file, "w") as f: + f.write( +""" +void f_i() +{ + (void)(*((int*)0)); +} +""") + + args = [ + '-q', + '--template=simple', + '--include=inc.h', + str(test_file) + ] + + exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) + assert exitcode == 0 + assert stdout == '' + assert stderr.splitlines() == [ + 'inc.h:4:14: error: Null pointer dereference: (int*)0 [nullPointer]' + ] + + +def test_dui_include_relative_missing(tmp_path): + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write('void f() {}') + + inc_file = tmp_path / 'inc.h' + with open(inc_file, "w") as f: + f.write( +""" +void f_i() +{ + (void)(*((int*)0)); +} +""") + + args = [ + '-q', + '--template=simple', + '--include=inc.h', + str(test_file) + ] + + exitcode, stdout, stderr = cppcheck(args,) + assert exitcode == 0 + assert stdout == '' + assert stderr.splitlines() == [ + f"{test_file}:0:0: error: Can not open include file 'inc.h' that is explicitly included. [missingIncludeExplicit]" + ] + + +def test_dui_include_absolute_missing(tmp_path): # #14675 + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write('void f() {}') + + args = [ + '-q', + '--template=simple', + '--include=/share/include/missing.h', + str(test_file) + ] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0 + assert stdout == '' + assert stderr.splitlines() == [ + f"{test_file}:0:0: error: Can not open include file '/share/include/missing.h' that is explicitly included. [missingIncludeExplicit]" + ] \ No newline at end of file