Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added Rose checker algorithm

...

  1. The incomplete array type must be the last element within the structure.
  2. There cannot be an array of structures that contain flexible array members.
  3. Structures that contain a flexible array member cannot be used as a member in the middle of another structure.
  4. The sizeof operator cannot be applied to a flexible array.

Automated Detection

The tool Compass / ROSE could try flagging violations of this rule simply by searching for structs where the last element is an array, with a small index (0 or 1). Alternately, it could flag violations by searching for arguments to malloc() of the form sizeof( struct) * sizeof( arraytype ) - 1.

Risk Assessment

Failing to use the correct syntax can result in undefined behavior, although the incorrect syntax will work on most implementations.

...