C and C++ Binaries


LANG.METRIC.VG_P : High Cyclomatic Complexity (Procedure)

Summary

A procedure's cyclomatic complexity is greater than 20.

Properties

Class Name High Cyclomatic Complexity (Procedure)
Significance style
Mnemonic LANG.METRIC.VG_P
Categories
CWE CWE:1121 Excessive McCabe Cyclomatic Complexity
JSF++ JSF++:3 All functions shall have a cyclomatic complexity number of 20 or less.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="High Cyclomatic Complexity (Procedure)"

Example

static int low_cyclomatic_complexity(int i) {      // ok: cyclomatic complexity <20
  int rv = 0;
  if (i) {
    rv = 1;
  }
  return rv;
}

// 'High Cyclomatic Complexity (Procedure)' warning issued on following line
// - cyclomatic complexity of this procedure is >20
static int high_cyclomatic_complexity(int a, int b, int c, int d, int e) {
  int rv = 0;
  if (a) {
    rv += 1;
    if (b) {
      rv += 1;
      if (c) {
        rv +=1;
        if (d) {
          rv +=1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
        else {
          rv -= 1;
          if (e) { rv += 1; }
          else { rv -= 1; }  
        }  
      }
      else {
        rv -=1;
        if (d) {
          rv +=1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
        else {
          rv -= 1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
      }
    }
    else {
      rv -= 1;
           if (c) {
        rv +=1;
        if (d) {
          rv +=1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
        else {
          rv -= 1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
      }
      else {
        rv -=1;
        if (d) {
          rv +=1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
        else {
          rv -= 1;
          if (e) { rv += 1; }
          else { rv -= 1; }
        }
      }
    }
  }
  else {
    rv -= 1;
    if (b) {
      rv += 1;
      if (c) {
        rv +=1;
        if (d) { rv +=1; }
        else { rv -=1; }
      }
      else { rv -=1; }
    }
    else {
      rv -= 1;
      if (c) { rv +=1; }
      else { rv -=1; }
    }
  }
  return rv;
}

Relevant Configuration File Parameters

This class is implemented using a METRIC_WARNING_* rule set in the general template configuration file.

To adjust the triggering condition for this class, edit the corresponding METRIC_WARNING_CONDITION.

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