summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coccinelle/empty-to-null.cocci5
-rw-r--r--coccinelle/mfree_return.cocci8
-rw-r--r--coccinelle/strempty.cocci48
3 files changed, 39 insertions, 22 deletions
diff --git a/coccinelle/empty-to-null.cocci b/coccinelle/empty-to-null.cocci
index fbc75b9c34..bc6c656e79 100644
--- a/coccinelle/empty-to-null.cocci
+++ b/coccinelle/empty-to-null.cocci
@@ -1,5 +1,8 @@
@@
+/* Avoid running this transformation on the empty_to_null function itself */
+position p : script:python() { p[0].current_element != "empty_to_null" };
expression s;
@@
-- isempty(s) ? NULL : s
+
+- isempty@p(s) ? NULL : s
+ empty_to_null(s)
diff --git a/coccinelle/mfree_return.cocci b/coccinelle/mfree_return.cocci
index 8119fe07f2..15e6c7d566 100644
--- a/coccinelle/mfree_return.cocci
+++ b/coccinelle/mfree_return.cocci
@@ -1,6 +1,8 @@
@@
-expression p;
+/* Avoid running this transformation on the mfree function itself */
+position p : script:python() { p[0].current_element != "mfree" };
+expression e;
@@
-- free(p);
+- free@p(e);
- return NULL;
-+ return mfree(p);
++ return mfree(e);
diff --git a/coccinelle/strempty.cocci b/coccinelle/strempty.cocci
index 13ceb338f1..7901da3652 100644
--- a/coccinelle/strempty.cocci
+++ b/coccinelle/strempty.cocci
@@ -1,48 +1,60 @@
@@
+/* Avoid running this transformation on the strempty function itself */
+position p : script:python() { p[0].current_element != "strempty" };
expression s;
@@
-- s ?: ""
+(
+- s@p ?: ""
+ strempty(s)
-@@
-expression s;
-@@
-- s ? s : ""
+|
+- s@p ? s : ""
+ strempty(s)
+)
+
@@
+position p : script:python() { p[0].current_element != "strempty" };
expression s;
@@
-- if (!s)
+- if (!s@p)
- s = "";
+ s = strempty(s);
+
@@
+position p : script:python() { p[0].current_element != "strnull" };
expression s;
@@
-- s ?: "(null)"
+(
+- s@p ?: "(null)"
+ strnull(s)
-@@
-expression s;
-@@
-- s ? s : "(null)"
+|
+- s@p ? s : "(null)"
+ strnull(s)
+)
+
@@
+position p : script:python() { p[0].current_element != "strnull" };
expression s;
@@
-- if (!s)
+- if (!s@p)
- s = "(null)";
+ s = strnull(s);
+
@@
+position p : script:python() { p[0].current_element != "strna" };
expression s;
@@
-- s ?: "n/a"
+(
+- s@p ?: "n/a"
+ strna(s)
-@@
-expression s;
-@@
-- s ? s : "n/a"
+|
+- s@p ? s : "n/a"
+ strna(s)
+)
+
@@
+position p : script:python() { p[0].current_element != "strna" };
expression s;
@@
-- if (!s)
+- if (!s@p)
- s = "n/a";
+ s = strna(s);