Size of variable-length array is zero or negative
This defect occurs when size of a variable-length array is zero or negative.
If the size of a variable-length array is zero or negative, unexpected behavior can occur, such as stack overflow.
When you declare a variable-length array as a local variable in a function:
If you use a function parameter as the array size, check that the parameter is positive.
If you use the result of a computation on a function parameter as the array size, check that the result is positive.
You can place a test for positive value either before the function call or the array declaration in the function body.
| Group: Programming |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax: NON_POSITIVE_VLA_SIZE |
| Impact: High |
| CWE ID: 687 |