Memory allocation ignores flexible array member
This defect occurs when:
You define an object with a flexible array member of unknown size at compilation time.
You make an assignment between structures with a flexible array member without using
memcpy() or a similar function.
You use a structure with a flexible array member as an argument to a function and pass the argument by value.
Your function returns a structure with a flexible array member.
A flexible array member has no array size specified and is the last element of a structure with at least two named members.
If the size of the flexible array member is not defined, it is ignored when allocating memory for the containing structure. Accessing such a structure has undefined behavior.
Use malloc() or a similar function to allocate memory for a
structure with a flexible array member.
Use memcpy() or a similar function to copy a structure with a
flexible array member.
Pass a structure with a flexible array member as a function argument by pointer.
| Group: Programming |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
FLEXIBLE_ARRAY_MEMBER_STRUCT_MISUSE
|
| Impact: Low |