Variable length array with non-positive size
Size of variable-length array is zero or negative
Description
This defect occurs when size of a variable-length array is zero or negative.
Risk
If the size of a variable-length array is zero or negative, unexpected behavior can occur, such as stack overflow.
Fix
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.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax:
NON_POSITIVE_VLA_SIZE |
Impact: High |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)