]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add semantic patch to find void f() { ... return ((void)g())); ... }
authorOndřej Surý <ondrej@isc.org>
Fri, 6 Dec 2019 12:29:04 +0000 (13:29 +0100)
committerMatthijs Mekking <matthijs@isc.org>
Fri, 6 Dec 2019 12:42:18 +0000 (13:42 +0100)
When a function returns void, it can be used as an argument to return in
function returning also void, e.g.:

void in(void) {
  return;
}

void out(void) {
  return (in());
}

while this is legal, it should be rewritten as:

void out(void) {
  in();
  return;
}

The semantic patch just find the occurrences, and they need to be fixed
by hand.

cocci/return-void-from-void.spatch [new file with mode: 0644]

diff --git a/cocci/return-void-from-void.spatch b/cocci/return-void-from-void.spatch
new file mode 100644 (file)
index 0000000..fcc639f
--- /dev/null
@@ -0,0 +1,19 @@
+@ rule1 @
+identifier f1;
+@@
+
+void f1(...)
+{
+...
+}
+
+@ rule2 @
+identifier rule1.f1;
+identifier f2;
+@@
+
+void f2(...) {
+...
+* return(f1(...));
+...
+}