aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorJosh Triplett <josh@freedesktop.org>2006-09-13 15:01:15 -0700
committerJosh Triplett <josh@freedesktop.org>2006-09-13 15:14:00 -0700
commit8aed19aea597dd467e0de3402ed7e6feae70394c (patch)
tree0b741efa1f3ce367290c4e171ac4fcd48d0aa9b7 /validation
parent27ff96a96c95d0171f3215458dd5a2ebc4bfafbf (diff)
downloadsparse-dev-8aed19aea597dd467e0de3402ed7e6feae70394c.tar.gz
"Initializer entry defined twice" should not trigger with zero-size fields
If a field of a structure has size 0 (which happens with an empty struct), the subsequent field will have the same offset. Assigning to both thus triggers the "Initializer entry defined twice" error, which should not happen. Change verify_nonoverlapping to not warn about overlaps where the first field has size 0. Add a validation file (validation/initializer-entry-defined-twice.c) for this warning, which covers two cases where it should trigger (same struct field twice; two fields of a union) and this case where it should not. Signed-off-by: Josh Triplett <josh@freedesktop.org>
Diffstat (limited to 'validation')
-rw-r--r--validation/initializer-entry-defined-twice.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/validation/initializer-entry-defined-twice.c b/validation/initializer-entry-defined-twice.c
new file mode 100644
index 00000000..80434f1c
--- /dev/null
+++ b/validation/initializer-entry-defined-twice.c
@@ -0,0 +1,43 @@
+/* Tests for the "Initializer entry defined twice" warning. */
+
+/* Initializing a struct field twice should trigger the warning. */
+struct normal {
+ int field1;
+ int field2;
+};
+
+struct normal struct_error = {
+ .field1 = 0,
+ .field1 = 0
+};
+
+/* Initializing two different fields of a union should trigger the warning. */
+struct has_union {
+ int x;
+ union {
+ int a;
+ int b;
+ } y;
+ int z;
+};
+
+struct has_union union_error = {
+ .y = {
+ .a = 0,
+ .b = 0
+ }
+};
+
+/* Empty structures can make two fields have the same offset in a struct.
+ * Initialzing both should not trigger the warning. */
+struct empty { };
+
+struct same_offset {
+ struct empty field1;
+ int field2;
+};
+
+struct same_offset not_an_error = {
+ .field1 = { },
+ .field2 = 0
+};