NonEmptyCaseWithoutBreak is reported - existing returns are not seen by SonarQube

  • versions used (SonarQube Version 7.2.1 (build 14109), Scanner 3.2.0.1227)

SonarQube reported:
End this switch case with an unconditional break, continue, return or throw statement.

In my opnion there is return statement in any case but it is not found by SonarQube.

 switch (Operation)
  {
    case WRITE_IN_VALID_PAGE: /* ---- Write operation ---- */
      if (pagestatus1 == VALID_PAGE)
      {
        /* Page0 receiving data */
        return ((pagestatus0 == RECEIVE_DATA) ? PAGE0 : PAGE1);
      }
      else
        if (pagestatus0 == VALID_PAGE)
      {
        /* Page1 receiving data */
        return ((pagestatus1 == RECEIVE_DATA) ? PAGE1 : PAGE0);
      }
      else
      {
        return NO_VALID_PAGE; /* No valid Page */
      }
    case READ_FROM_VALID_PAGE: /* ---- Read operation ---- */

Hi,

Could you clarify by specifying which language this is from?

 
Ann

Hi,

it is ‘C’ code.

Thomas

Hello Thomas,

This rule is specified according to the Misra standard, and it behaves as expected in this standard:

An unconditional break statement shall terminate every switch-clause

We agree that it may seem a little bit too strict, because code such as the one you presented cannot fall through to the next case. We might revisit this rule in future versions, but nothing is written in stone yet.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.