...
Code Block | ||
---|---|---|
| ||
void func(size_t s) { int vla[s]; /* ... */ } /* ... */ func(size); /* ... */ |
Compliant Code Solution
Validate size arguments used in VLA declarations. The solution below ensures the size argument, s
, used to allocate vla
is in a valid range: 1 to a user defined constant.
Code Block | ||
---|---|---|
| ||
#define MAX_ARRAY 1024 void func(size_t s) { int vla[s]; /* ... */ } /* ... */ if (s < MAX_ARRAY && s != 0) { func(s); } else { /* Handle Error */ } /* ... */ |
Implementation Details
Variable length arrays are not supported by Microsoft compilers.
...