[previous] 2851 [next] Definite: Implicit conversion to a signed integer type of insufficient size.
Conversion to signed

A definite anomaly has been detected. A conversion to a signed type is being performed but examination of the context indicates that the value being converted is always too large to be represented in this type. The result will 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 below, it can be seen that in each case, the value of the expression being assigned to sca 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 = sia;     /* 2851 3756 */
    }

    if (uia > 127u)
    {
        sca = uia;     /* 2851 3767 */
    }
}


MISRA C:2012 Rules applicable to message 2851:

Rule-10.3  (Required) The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.


See also:

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