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

An apparent anomaly has been detected. An expression is being cast to a signed type, but examination of the context indicates that the value being converted will sometimes be unrepresentable 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 shown below, unless the if statement is redundant, the code implies that the value of sia will sometimes exceed 127. If it does, behavior in the subsequent assignment operation will be implementation-defined.


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

void foo(signed int sia)
{
    signed char sca;

    if (sia > 200)
    {

    }

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

See also:

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