Synopsis: | Array bounds shall be specified as integral constant expressions. |
Language: | C |
Severity Level: | 5 |
Category: | Declarations |
Description: |
Justification Constant expressions enable tooling to check if indexing is in the defined array range. Also, compile time undefined array size can lead to uncontrollable excessive stack usage. Example 1 #define CCBB_ARRAY_LEN 3 #define CCBB_ARRAY_SIZE (CCBB_ARRAY_LEN + 1) static char ccbb_array[CCBB_ARRAY_SIZE] = ""; /* RIGHT */ Example 2 static void ccbb_f(int s) { int a[s]; /* WRONG: array size depends on param.*/ ... } Note Allocate an array dynamically when using large arrays (> 1kB). |