From 75f6a1fb4a77785d87d3c97b91b826f40f6f05ae Mon Sep 17 00:00:00 2001 From: bruntib Date: Thu, 1 Aug 2024 16:17:18 +0200 Subject: [PATCH] [fix] Don't enable checkers by suffix Currently, checkers can be enabled by checker name prefix. For example, "--enable unix" enables all checkers starting with "unix". However, checkers shouldn't be enabled by suffix match: "--enable Malloc" shouldn't enable "unix.Malloc" checker. The source of the confusion was that having "unix.Stream" checker in the "default" profile also enabled "alpha.unix.Stream", which is not an intended behavior. --- analyzer/codechecker_analyzer/analyzers/config_handler.py | 3 +-- analyzer/tests/unit/test_checker_handling.py | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/analyzer/codechecker_analyzer/analyzers/config_handler.py b/analyzer/codechecker_analyzer/analyzers/config_handler.py index e4c45eb9f0..8e4c0db32b 100644 --- a/analyzer/codechecker_analyzer/analyzers/config_handler.py +++ b/analyzer/codechecker_analyzer/analyzers/config_handler.py @@ -90,8 +90,7 @@ def set_checker_enabled(self, checker_name, enabled=True): changed_states = [] for ch_name, values in self.__available_checkers.items(): - if ch_name.startswith(checker_name) or \ - ch_name.endswith(checker_name): + if ch_name.startswith(checker_name): _, description = values state = CheckerState.ENABLED if enabled \ else CheckerState.DISABLED diff --git a/analyzer/tests/unit/test_checker_handling.py b/analyzer/tests/unit/test_checker_handling.py index 1d62348d76..0deebdf4a5 100644 --- a/analyzer/tests/unit/test_checker_handling.py +++ b/analyzer/tests/unit/test_checker_handling.py @@ -250,6 +250,13 @@ def f(checks, checkers): self.assertTrue(all_with_status(CheckerState.DISABLED) (cfg_handler.checks(), cert_guideline)) + cfg_handler = ClangSA.construct_config_handler(args) + cfg_handler.initialize_checkers(checkers, + [('default', False), + ('DeadStores', True)]) + self.assertTrue(all_with_status(CheckerState.DISABLED) + (cfg_handler.checks(), default_profile)) + # Enable "LOW" severity checkers. cfg_handler = ClangSA.construct_config_handler(args) cfg_handler.initialize_checkers(checkers,