[previous] 2858 [next] Suspicious: Casting to a signed integer type of insufficient size.
Conversion to signed

Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable.

The value of an expression is being cast to a signed integer type. Examination of the immediate context suggests that the value of this expression could sometimes be too large to be represented in this type.

For example, in the code shown below, the value being cast to type signed char will be '128' (which is unrepresentable) unless the parameter 'n' is greater than 0.


/*PRQA S 272,2017,2983,2986,3120,3195,3199,3203,3227,3408,3602 ++*/

void foo(int n)
{
   signed int  sia = 128;
   signed char sca;
   int         i;

   for (i = 0; i < n; ++i)
   {
      sia = sia - 10;
   }

   sca = (signed char)sia;                     /* 2858 */
}


No MISRA-C:2004 Rules applicable to message 2858


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents