Skip to content

Commit

Permalink
[cmd] Checker name prefixes are meant along separator characters
Browse files Browse the repository at this point in the history
Checkers can be enabled by groups, e.g. unix.cstring enables all
checkers starting with this prefix. However, unix.cs is not a checker
group so this shouldn't be allowed. In this case an error message is
printed and analysis doesn't start.
  • Loading branch information
bruntib committed Aug 14, 2024
1 parent 9693dbb commit 8893ecd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion analyzer/codechecker_analyzer/analyzers/config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from enum import Enum
import collections
import platform
import re

from codechecker_analyzer import analyzer_context
from codechecker_common.logger import get_logger
Expand Down Expand Up @@ -88,9 +89,10 @@ def set_checker_enabled(self, checker_name, enabled=True):
Explicitly handle checker state, keep description if already set.
"""
changed_states = []
regex = "^" + re.escape(str(checker_name)) + "\\b.*$"

for ch_name, values in self.__available_checkers.items():
if ch_name.startswith(checker_name):
if re.match(regex, ch_name):
_, description = values
state = CheckerState.ENABLED if enabled \
else CheckerState.DISABLED
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def available(ordered_checkers, available_checkers):

name_match = False
for available_checker in available_checkers:
regex = "^" + re.escape(str(checker_name)) + ".*$"
regex = "^" + re.escape(str(checker_name)) + "\\b.*$"
c_name = available_checker
match = re.match(regex, c_name)
if match:
Expand Down
21 changes: 21 additions & 0 deletions analyzer/tests/unit/test_checker_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ def f(checks, checkers):
self.assertTrue(all_with_status(CheckerState.ENABLED)
(cfg_handler.checks(), low_severity))

# Enable checkers with a checker group prefix.
cfg_handler = ClangSA.construct_config_handler(args)
cfg_handler.initialize_checkers(checkers,
[('default', False),
('cplusplus.NewDelete', True)])
self.assertTrue(
all_with_status(CheckerState.ENABLED)
(cfg_handler.checks(), ['cplusplus.NewDelete']))
self.assertTrue(
all_with_status(CheckerState.DISABLED)
(cfg_handler.checks(), ['cplusplus.NewDeleteLeaks']))

cfg_handler = ClangSA.construct_config_handler(args)
cfg_handler.initialize_checkers(checkers,
[('default', False),
('cplusplus', True)])
self.assertTrue(
all_with_status(CheckerState.ENABLED)
(cfg_handler.checks(), ['cplusplus.NewDelete',
'cplusplus.NewDeleteLeaks']))

# Test if statisticsbased checkers are enabled by --stats flag
# by default.
stats_capable = strtobool(
Expand Down

0 comments on commit 8893ecd

Please sign in to comment.