C-style array declaration in C++
ID |
c.maintainability.avoid_c_arrays |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Modernization |
Language |
C / C++ |
Description
A C-style array does not carry its size, decays to a pointer, and has no bounds-aware interface. Prefer std::array<T, N> for fixed-size storage or std::vector<T> for dynamic storage, which know their length and interoperate with the standard algorithms.
Rationale
A C-style array does not carry its size, decays to a pointer, and has no bounds-aware interface. Prefer std::array<T, N> for fixed-size storage or std::vector<T> for dynamic storage, which know their length and interoperate with the standard algorithms.
The following code illustrates the pattern detected by this rule:
void f() {
// FLAGGED: C-style array declaration in C++
int a[10];
// FLAGGED: C-style array declaration in C++
char buf[256];
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.