aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/eval
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-07 04:22:15 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-09 23:29:10 +0100
commit82d8c05866c84a04cc5ecba74365573b4c29fcbc (patch)
treed409c2da9699f45df1fada4741becde581f16429 /validation/eval
parent9b2efc158c5c9700ffe355c59356879df7c9cc12 (diff)
downloadsparse-dev-82d8c05866c84a04cc5ecba74365573b4c29fcbc.tar.gz
fix premature examination of dereferenced object
in the fixes 696b243a5ae0 ("fix: evaluate_dereference() unexamined base type"), the pointer's examination was done prematurely, before the undereferenceable types are filtered out. This allows to examine the base abstract types when the expression was in fact not dereferenceable. Fix that by moving the examination to the top of the SYM_PTR's case since only pointers are concerned. Fixes: 696b243a5ae0 ("fix: evaluate_dereference() unexamined base type") Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/eval')
-rw-r--r--validation/eval/premature-examination.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/validation/eval/premature-examination.c b/validation/eval/premature-examination.c
new file mode 100644
index 00000000..bd2ffa90
--- /dev/null
+++ b/validation/eval/premature-examination.c
@@ -0,0 +1,27 @@
+extern int i;
+
+int foo(void)
+{
+ return *i;
+}
+
+int bar(void)
+{
+ return i[0];
+}
+
+int *qux(void)
+{
+ return &i[0];
+}
+
+/*
+ * check-name: premature-examination
+ * check-command: sparse -Wno-decl $file
+ *
+ * check-error-start
+eval/premature-examination.c:5:16: error: cannot dereference this type
+eval/premature-examination.c:10:17: error: cannot dereference this type
+eval/premature-examination.c:15:18: error: cannot dereference this type
+ * check-error-end
+ */