[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 */
    }
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents