[PATCH 11/13] flex-array: warn an arrays containing a flexible array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



An array of some aggregate type containing, possibly recursively,
a flexible array is pretty non-sensical. So, add an option
-Wflexible-array-array to warn on such usage.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 options.c                     | 2 ++
 options.h                     | 1 +
 sparse.1                      | 7 +++++++
 symbol.c                      | 2 ++
 validation/flex-array-array.c | 1 -
 5 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/options.c b/options.c
index ce88fbf6ed61..a8129ac1e952 100644
--- a/options.c
+++ b/options.c
@@ -100,6 +100,7 @@ int Wdesignated_init = 1;
 int Wdo_while = 0;
 int Wenum_mismatch = 1;
 int Wexternal_function_has_definition = 1;
+int Wflexible_array_array = 1;
 int Wflexible_array_sizeof = 0;
 int Wimplicit_int = 1;
 int Winit_cstring = 0;
@@ -841,6 +842,7 @@ static const struct flag warnings[] = {
 	{ "do-while", &Wdo_while },
 	{ "enum-mismatch", &Wenum_mismatch },
 	{ "external-function-has-definition", &Wexternal_function_has_definition },
+	{ "flexible-array-array", &Wflexible_array_array },
 	{ "flexible-array-sizeof", &Wflexible_array_sizeof },
 	{ "implicit-int", &Wimplicit_int },
 	{ "init-cstring", &Winit_cstring },
diff --git a/options.h b/options.h
index feb351a36c9e..7bcf925b6912 100644
--- a/options.h
+++ b/options.h
@@ -99,6 +99,7 @@ extern int Wdesignated_init;
 extern int Wdo_while;
 extern int Wenum_mismatch;
 extern int Wexternal_function_has_definition;
+extern int Wflexible_array_array;
 extern int Wflexible_array_sizeof;
 extern int Wimplicit_int;
 extern int Winit_cstring;
diff --git a/sparse.1 b/sparse.1
index 5f98df33a231..c1a74153c618 100644
--- a/sparse.1
+++ b/sparse.1
@@ -257,6 +257,13 @@ Sparse issues these warnings by default.  To turn them off, use
 \fB\-Wno\-external\-function\-has\-definition\fR.
 .
 .TP
+.B -Wflexible-array-array
+Warn about arrays of structures containing a flexible array.
+
+Sparse issues these warnings by default. To turn them off, use
+\fB-Wno-flexible-array-array\fR.
+.
+.TP
 .B -Wflexible-array-sizeof
 Warn about using the sizeof operator on a structure containing a flexible array,
 possibly recursively.
diff --git a/symbol.c b/symbol.c
index bffdc135ba69..02b9066e966a 100644
--- a/symbol.c
+++ b/symbol.c
@@ -267,6 +267,8 @@ static struct symbol * examine_array_type(struct symbol *sym)
 			bit_size = -1;
 		}
 	}
+	if (has_flexible_array(base_type) && Wflexible_array_array)
+		warning(sym->pos, "array of flexible structures");
 	alignment = base_type->ctype.alignment;
 	if (!sym->ctype.alignment)
 		sym->ctype.alignment = alignment;
diff --git a/validation/flex-array-array.c b/validation/flex-array-array.c
index bda80d7a0a20..921a0698bb28 100644
--- a/validation/flex-array-array.c
+++ b/validation/flex-array-array.c
@@ -8,7 +8,6 @@ static struct s a[2];
 /*
  * check-name: flex-array-array
  * check-command: sparse -Wflexible-array-array $file
- * check-known-to-fail
  *
  * check-error-start
 flex-array-array.c:6:18: warning: array of flexible structures
-- 
2.28.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux