Missing null in string array
String does not terminate with null character
Description
This defect occurs when a string does not have enough
space to terminate with a null character '\0'
.
This defect applies only for projects in C.
Risk
A buffer overflow can occur if you copy a string to an array without assuming the implicit null terminator.
Fix
If you initialize a character array with a literal, avoid specifying the array bounds.
char three[] = "THREE";
If the issue occurs after initialization, you might have to increase the size of the array by one to account for the null terminator.
In certain circumstances, you might want to initialize the character array with a sequence of characters instead of a string. In this situation, add comments to your result or code to avoid another review. See:
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
Group: Programming |
Language: C |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: MISSING_NULL_CHAR |
Impact: Low |
Version History
Introduced in R2013b
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)