Showing posts with label maintainability. Show all posts
Showing posts with label maintainability. Show all posts

Thursday, March 25, 2010

switch shall have at least one case




Every switch statement shall have at least one case clause (misra2004_15_5_AvoidSwitchWithNoCase.rule)


Description

Every switch statement shall have at least one case.

Benefits:

Provides maintainability of 'switch' statement.

Example:

void foo(int i)
{

   switch(i)      /* Violation */
   {

       default:
           ;
   }

}

Repair:

void foo(int i)
{
   switch(i)      /* OK */
   {
     case 1:
     {

     }
     default:
           ;

   }

}

References:

MISRA-C:2004 Guidelines for the use of the C language in critical systems
Chapter 6, Section 15

Author
ParaSoft
 
 
 
Tags: switch, case, maintainability, Guidelines, critical systems
 
 

Monday, March 22, 2010

Avoid assignment in if




Avoid assignment in if statement condition (IfAssign.rule)


Description:

This rule checks whether your code has assignment within an if statement condition. This rule is enabled by default.

Benefits:

Legibility and maintainability.

Assignment in the context of an if statement is easily confused with equality.

Example:

void foo(int a, int b) {

  if ( a = b ) {}  // Violation

}

Repair:

void foo(int a, int b) {

  if ( a == b ) {} // OK
}

Author
ParaSoft




Labels