linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] add warnings for flexible arrays
@ 2020-09-30 23:18 Luc Van Oostenryck
  2020-09-30 23:18 ` [PATCH 01/13] flex-array: add testcases Luc Van Oostenryck
                   ` (13 more replies)
  0 siblings, 14 replies; 20+ messages in thread
From: Luc Van Oostenryck @ 2020-09-30 23:18 UTC (permalink / raw)
  To: linux-sparse; +Cc: Linus Torvalds, Luc Van Oostenryck

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

-- 
2.28.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-10-01 19:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 23:18 [PATCH 00/13] add warnings for flexible arrays Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 01/13] flex-array: add testcases Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 02/13] flex-array: factor out common part of lay_out_{struct,union}() Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 03/13] flex-array: do not lay out invalid struct members Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 04/13] flex-array: flexible array members have zero size and alignment is OK Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 05/13] flex-array: detect structures with a flexible array member Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 06/13] flex-array: warn on flexible arrays in unions Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 07/13] flex-array: warn if flexible array is not last Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 08/13] flex-array: identify structures with a flexible array member Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 09/13] flex-array: add helper has_flexible_array() Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 10/13] flex-array: warn when using sizeof() on a flexible array Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 11/13] flex-array: warn an arrays containing " Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 12/13] flex-array: warn on flexible array in nested aggregate types Luc Van Oostenryck
2020-09-30 23:18 ` [PATCH 13/13] flex-array: warn when a flexible array member has some padding Luc Van Oostenryck
2020-10-01 16:34   ` Linus Torvalds
2020-10-01 19:17     ` Luc Van Oostenryck
2020-10-01 19:27       ` Linus Torvalds
2020-10-01 19:41         ` Luc Van Oostenryck
2020-10-01 19:51           ` Luc Van Oostenryck
2020-10-01 16:36 ` [PATCH 00/13] add warnings for flexible arrays Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).