C and C++ Binaries


Custom Metric-Based Warning Classes

CodeSonar provides configuration parameters that allow users to specify custom warning classes based on metric values. A custom metric warning class is defined using five settings:

METRIC_WARNING_CLASS_NAME The warning class name.
METRIC_WARNING_CONDITION A condition of the form metric_tag[metric_granularity] op num, where op is one of <, <=, >, >=.

A warning will be triggered whenever the value of the specified metric falls in the specified range.

METRIC_WARNING_SIGNIFICANCE
A Significance value for the class.
METRIC_WARNING_CATEGORIES
[optional]
Categories associated with the warning class.
METRIC_WARNING_BASE_RANK
[optional]
The base rank for any triggered warning.

Example Custom Metric-Based Classes

The comments in the general template configuration file include three example classes implemented with METRIC_WARNING_* rules. To include checks for any of these classes:

High Cyclomatic Complexity

With this class enabled, CodeSonar will issue a High Cyclomatic Complexity warning for any function with a cyclomatic complexity of 20 or more.

#     METRIC_WARNING_CONDITION = vG[PROCEDURE] >= 20
#     METRIC_WARNING_CLASS_NAME = High Cyclomatic Complexity
#     METRIC_WARNING_CATEGORIES = METRIC.VG
#     METRIC_WARNING_BASE_RANK = 5.0
#     METRIC_WARNING_SIGNIFICANCE = STYLE

Large procedure

With this class enabled, CodeSonar will issue a Large procedure warning for any function containing more than 100 lines with code.

#     METRIC_WARNING_CONDITION = LCode[PROCEDURE] > 100
#     METRIC_WARNING_CLASS_NAME = Large procedure
#     METRIC_WARNING_CATEGORIES = METRIC.LCODE
#     METRIC_WARNING_BASE_RANK = 1.0
#     METRIC_WARNING_SIGNIFICANCE = STYLE

Too few comments

With this class enabled, CodeSonar will issue a Too few comments warning for any function containing fewer than 5 lines with comments.

#     METRIC_WARNING_CONDITION = LCom[PROCEDURE] < 5
#     METRIC_WARNING_CLASS_NAME = Too few comments
#     METRIC_WARNING_CATEGORIES = METRIC.LCOM
#     METRIC_WARNING_BASE_RANK = 2.0
#     METRIC_WARNING_SIGNIFICANCE = STYLE

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.