Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3955

"if" and "while" statements should not lead to the execution of empty statements

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Closed
    • Resolution: Duplicate
    • Labels:
    • Message:
      Remove this unexpected trailing semi-colon.
    • Highlighting:
      Hide

      The trailing semi-colon closing the empty statement.

      Show
      The trailing semi-colon closing the empty statement.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C#, C, C++, Java, JavaScript, Objective-C, PHP, PL/SQL
    • Irrelevant for Languages:
      Python, Swift
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2mn
    • Analysis Scope:
      Main Sources, Test Sources
    • CERT:
      MSC51-J., EXP15-C.

      Description

      There is no point in creating a branch in the code only to execute an empty statement. Such code can only be due to the presence of an unexpected trailing semi-colon.

      Noncompliant Code Example

      if(foo);      //Noncompliant, the semi-colon must be removed
        trigger(action1);  // executes unconditionally
      else if (bar);    //Noncompliant, the semi-colon must be removed
        trigger(action2);  // executes unconditionally
      
      while (condition);  // Noncompliant
        doTheThing();  // executes once, unconditionally 
      

      See

      • CERT, MSC51-J. - Do not place a semicolon immediately following an if, for, or while condition
      • CERT, EXP15-C. - Do not place a semicolon on the same line as an if, for, or while statement

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: