aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-22 17:27:22 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-22 18:24:41 +0100
commit4480ef07d1187395ea8b277174ac2545254b40f0 (patch)
treebae417c4d5d0c61e43d2a461f5a478346965b6c5 /validation
parenteccfa2c15c5cc529a1cb998f59bf1dc799ed4004 (diff)
downloadsparse-dev-4480ef07d1187395ea8b277174ac2545254b40f0.tar.gz
warn if testing the address of an array
Testing the address of an array is quite suspicious: it's most probably the sign of an error somewhere. Furthermore, such uses always evaluate to true. So, add a warning about such use (but only if -Waddress was given).
Diffstat (limited to 'validation')
-rw-r--r--validation/cond-address-array.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/validation/cond-address-array.c b/validation/cond-address-array.c
new file mode 100644
index 00000000..e1d2f87f
--- /dev/null
+++ b/validation/cond-address-array.c
@@ -0,0 +1,26 @@
+int foo(void) {
+ extern int a[];
+
+ if (a)
+ return 1;
+ return 0;
+}
+
+int bar(void) {
+ int a[2];
+
+ if (a)
+ return 1;
+ return 0;
+}
+
+/*
+ * check-name: cond-address-array.c
+ * check-command: test-linearize -Wno-decl -Waddress $file
+ * check-output-ignore
+ *
+ * check-error-start
+cond-address-array.c:4:13: warning: the address of an array will always evaluate as true
+cond-address-array.c:12:13: warning: the address of an array will always evaluate as true
+ * check-error-end
+ */