[previous] 3132 [next] Hard coded 'magic' number, '%s', used to define the size of an array.
Constants

An integer constant has been used to define the size of an array.

If the size of the array is also used in other contexts it may be better to define a macro or an enum constant in an appropriate location. This will improve maintainability by avoiding duplication. Giving the constant a name may also improve readability. Message 3132 will not be generated and the macro or enum constant can be reused wherever needed.

Message 3132 is not generated on an array dimensioned to "1".

For example:


/*PRQA S 2017,2211,2213,3203,3205,3408,3602 ++*/

#define NEL 4
enum {FOUR = 4};

extern void foo(void)
{
    int  a[1];                                  /*              */
    int  b[4];                                  /* Message 3132 */
    int  c[NEL];                                /*              */
    int  d[FOUR];                               /*              */
    int i;

    for (i = 0; i < 4; ++i) { b[i] = 0; }       /* Message 3120 */

    for (i = 0; i < NEL; ++i) { c[i] = 0; }     /*              */

    for (i = 0; i < FOUR; ++i) { d[i] = 0; }    /*              */

}

See also:

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