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

A definite anomaly has been detected. A cast to a signed type is being performed but examination of the context indicates that the value being converted is never representable in this type. The result will always be implementation-defined.

For example, an object of type signed char can usually only represent values in the range -128 to 127. In the code shown below, it can be seen that in each case, the value of the expression being cast is outside this range.


/*PRQA S 273,1278,2017,2982,2983,2984,2986,3120,3195,3198,3199,3203,3227,3408,3602 ++*/

void foo(signed int sia, unsigned int uia)
{
    signed char sca;

    if (sia < -128)
    {
        sca = (signed char)sia;     /* 2856 */
    }

    if (uia > 127u)
    {
        sca = (signed char)uia;     /* 2856 */
    }
}


MISRA-C:2004 Rules applicable to message 2856:

Rule  3.1  (Required) All usage of implementation-defined behaviour shall be documented.


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