summaryrefslogtreecommitdiffstats
path: root/devel/coccinelle/ref-passed-variables-inited.cocci
diff options
context:
space:
mode:
Diffstat (limited to 'devel/coccinelle/ref-passed-variables-inited.cocci')
-rw-r--r--devel/coccinelle/ref-passed-variables-inited.cocci50
1 files changed, 50 insertions, 0 deletions
diff --git a/devel/coccinelle/ref-passed-variables-inited.cocci b/devel/coccinelle/ref-passed-variables-inited.cocci
new file mode 100644
index 0000000..0d19ff7
--- /dev/null
+++ b/devel/coccinelle/ref-passed-variables-inited.cocci
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2019-2020 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
+ *
+ *
+ * We require each local variable that
+ *
+ * - is passed to a function through a dereference (suggesting it serves
+ * possibly also or merely as one of the output value propagators seperate
+ * from actual return value if employed at all) and
+ *
+ * - is then subsequently reused (possibly naively expecting it will always
+ * have been initialized (in said function at latest) further in its scope,
+ *
+ * to _always_ be assuredly initialized to some determined value, so as to
+ * prevent a risk of accidentally accessing unspecified value subsequent
+ * to the return from the considered function, which might not have set
+ * that variable at all, lest it would touch it at all.
+ */
+
+virtual internal
+
+@ref_passed_variables_inited exists@
+identifier f_init, f_consume, var;
+type T;
+expression E, E_propagate;
+@@
+
+ T
+- var
++ var /*FIXME:initialize me*/
+ ;
+ ... when != var = E
+ f_init(..., &var, ...)
+ ... when != var = E
+(
+ return var;
+|
+ f_consume(..., var, ...)
+|
+ E_propagate = var
+|
+ &var
+|
+ *var
+)