Skip to content

add warnings for flexible arrays

Luc Van Oostenryck linux-sparse 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13flex-array: add testcasesvalidation/flex-array-align.c validation/flex-array-array.c validation/flex-array-error.c +3 more+133 -00 replies
2/13flex-array: factor out common part of lay_out_{struct,union}()symbol.c+8 -160 replies
3/13flex-array: do not lay out invalid struct memberssymbol.c+4 -20 replies
4/13flex-array: flexible array members have zero size and alignment is OKsymbol.c validation/flex-array-align.c+0 -20 replies
5/13flex-array: detect structures with a flexible array membersymbol.c+2 -00 replies
6/13flex-array: warn on flexible arrays in unionssymbol.c+3 -00 replies
7/13flex-array: warn if flexible array is not lastsymbol.c validation/flex-array-error.c+2 -10 replies
8/13flex-array: identify structures with a flexible array membersymbol.c symbol.h+7 -00 replies
9/13flex-array: add helper has_flexible_array()symbol.h+7 -00 replies
10/13flex-array: warn when using sizeof() on a flexible arrayevaluate.c options.c options.h +2 more+13 -10 replies
11/13flex-array: warn an arrays containing a flexible arrayoptions.c options.h sparse.1 +2 more+12 -10 replies
12/13flex-array: warn on flexible array in nested aggregate typesoptions.c options.h sparse.1 +2 more+14 -10 replies
13/13flex-array: warn when a flexible array member has some paddingoptions.c options.h sparse.1 +2 more+11 -15 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/13] add warnings for flexible arrays

Flexible array members have some restrictions (must be last in a structure, not in a union) and a number of dangerous or non-sensical usage (in an array, in nested structure or even using sizeof() on the containing structure). Sparse currently supports flexible array members but barely and doesn't help finding bugs related to them. This series aims at improving this:
* fix structure alignment in the presence of a flexible array member
* issue an error if the flexible array is not last or in a union
* add an option to issue a warning:
* on arrays of such 'flexible structures'
* when using sizeof() on the containing structure
* when declaring nested aggregate types with a flexible array member
* if the flexible array adds some padding to the structure

When used on the kernel (v5.9-rc1) this results in no errors but the following number of warnings:
90 array of flexible structures
5719 using sizeof on a flexible structure
1909 flexible array member has padding
888 nested flexible arrays

So, to begin with, the corresponding warning flags default to
-Wflexible-array-array -Wno-flexible-array-nested -Wno-flexible-array-padding -Wno-flexible-array-sizeof

Notes: implicit sizeof() on such 'flexible structures' like here

	under are not yet checked:
		struct s {
			...
			int flex[];
		} *dst, *src;
		...
		*dst = *src

Luc Van Oostenryck (13):
flex-array: add testcases
flex-array: factor out common part of lay_out_{struct,union}()
flex-array: do not lay out invalid struct members
flex-array: flexible array members have zero size and alignment is OK
flex-array: detect structures with a flexible array member
flex-array: warn on flexible arrays in unions
flex-array: warn if flexible array is not last
flex-array: identify structures with a flexible array member
flex-array: add helper has_flexible_array()
flex-array: warn when using sizeof() on a flexible array
flex-array: warn an arrays containing a flexible array
flex-array: warn on flexible array in nested aggregate types
flex-array: warn when a flexible array member has some padding

 evaluate.c                      |  3 ++
 options.c                       |  8 ++++++
 options.h                       |  4 +++
 sparse.1                        | 27 ++++++++++++++++++
 symbol.c                        | 50 +++++++++++++++++++++------------
 symbol.h                        |  8 ++++++
 validation/flex-array-align.c   | 18 ++++++++++++
 validation/flex-array-array.c   | 15 ++++++++++
 validation/flex-array-error.c   | 26 +++++++++++++++++
 validation/flex-array-nested.c  | 29 +++++++++++++++++++
 validation/flex-array-padding.c | 21 ++++++++++++++
 validation/flex-array-sizeof.c  | 18 ++++++++++++
 12 files changed, 209 insertions(+), 18 deletions(-)
 create mode 100644 validation/flex-array-align.c
 create mode 100644 validation/flex-array-array.c
 create mode 100644 validation/flex-array-error.c
 create mode 100644 validation/flex-array-nested.c
 create mode 100644 validation/flex-array-padding.c
 create mode 100644 validation/flex-array-sizeof.c
Signature · 1 line
2.28.0