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

An apparent anomaly has been detected. Preceding operations imply that it will sometimes be impossible to represent the value of this expression in the signed type to which it is being converted. The result will be implementation-defined.

For example, in the code shown below, the relational expression in the "if" statement implies that the value of sia is expected to exceed 127 - sometimes. If the size of a char is 8 bits, values of this magnitude cannot be represented. Of course, if the value of sia never exceeds 127, the conversion will preserve the value; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.


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

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

    if (sia > 127)
    {
        /* ... */
    }

    /* ... */

    sca = sia;                  /* 2852 3756 */
}

See also:

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