Showing posts with label critical systems. Show all posts
Showing posts with label critical systems. 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
 
 

Do not convert pointer to pointer




A cast should not be performed between a pointer to object type and a different pointer to object type (misra2004_11_4_DoNotConvertPointerToPointer.rule)


Description:

"A cast should not be performed between a pointer to object type and a different pointer to object type. Conversions of this type may be invalid if the new pointer type requires a stricter alignment."

Note: This rule skips casting of void type.

Benefits:

Prevents incorrect pointer alignment.

Example:

void foo( ) {
   int* pi;
   char* i;

   i = (char*) pi; // Violation
   i = (char*) &i; // Violation
}

Repair:

Do not convert pointer to different pointer.

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

Author
ParaSoft


Tags: cast, pointer, void, pointer alignment, MISRA, critical systems


Labels