summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2019-04-28 15:03:47 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2019-04-28 22:11:15 +0200
commit33af88cf70fce38a39642e92609cfba655925d55 (patch)
tree67f5296bbd8d6adb6de0658273ab825b10adf257
parenttree-wide: drop !! casts to booleans (diff)
downloadsystemd-33af88cf70fce38a39642e92609cfba655925d55.tar.xz
systemd-33af88cf70fce38a39642e92609cfba655925d55.zip
coccinelle: ignore macro transformations in the macros themselves
For example, the following transformation: - sizeof(s)-1 + STRLEN(s) would replace sizeof by STRLEN even in the STRLEN macro definition itself, which generates following nonsensical patch: --- src/basic/macro.h +++ /tmp/cocci-output-8753-b50773-macro.h @@ -182,7 +182,7 @@ static inline unsigned long ALIGN_POWER2 * Contrary to strlen(), this is a constant expression. * @x: a string literal. */ -#define STRLEN(x) (sizeof(""x"") - 1) +#define STRLEN(x) (STRLEN("" x "")) /* * container_of - cast a member of a structure out to the containing structure Let's exclude the macro itself from the transformation to avoid this
-rw-r--r--coccinelle/const-strlen.cocci4
-rw-r--r--coccinelle/debug-logging.cocci8
-rw-r--r--coccinelle/memzero.cocci8
3 files changed, 20 insertions, 0 deletions
diff --git a/coccinelle/const-strlen.cocci b/coccinelle/const-strlen.cocci
index 38bf9b118f..30a6e5a88e 100644
--- a/coccinelle/const-strlen.cocci
+++ b/coccinelle/const-strlen.cocci
@@ -1,8 +1,12 @@
@@
constant s;
@@
+(
+#define STRLEN
+&
- sizeof(s)-1
+ STRLEN(s)
+)
@@
constant s;
@@
diff --git a/coccinelle/debug-logging.cocci b/coccinelle/debug-logging.cocci
index 9084cf773b..a679dab011 100644
--- a/coccinelle/debug-logging.cocci
+++ b/coccinelle/debug-logging.cocci
@@ -1,8 +1,16 @@
@@
@@
+(
+#define DEBUG_LOGGING
+&
- _unlikely_(log_get_max_level() >= LOG_DEBUG)
+ DEBUG_LOGGING
+)
@@
@@
+(
+#define DEBUG_LOGGING
+&
- log_get_max_level() >= LOG_DEBUG
+ DEBUG_LOGGING
+)
diff --git a/coccinelle/memzero.cocci b/coccinelle/memzero.cocci
index ebdc3f6a2a..8198cc84b4 100644
--- a/coccinelle/memzero.cocci
+++ b/coccinelle/memzero.cocci
@@ -21,10 +21,18 @@ expression s;
@@
expression a, b;
@@
+(
+#define memzero
+&
- memset(a, 0, b)
+ memzero(a, b)
+)
@@
expression a, b;
@@
+(
+#define memzero
+&
- bzero(a, b)
+ memzero(a, b)
+)