]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: ignore macro transformations in the macros themselves
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 28 Apr 2019 13:03:47 +0000 (15:03 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 28 Apr 2019 20:11:15 +0000 (22:11 +0200)
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

coccinelle/const-strlen.cocci
coccinelle/debug-logging.cocci
coccinelle/memzero.cocci

index 38bf9b118fd5d01117edb2046ee0eaf1d49742cd..30a6e5a88ed80308e9a4ffcb27e310a0dbdb6310 100644 (file)
@@ -1,8 +1,12 @@
 @@
 constant s;
 @@
+(
+#define STRLEN
+&
 - sizeof(s)-1
 + STRLEN(s)
+)
 @@
 constant s;
 @@
index 9084cf773bf685af625e7861aed76305899c97a0..a679dab01150a38b212c61b1c53d38177cc2e694 100644 (file)
@@ -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
+)
index ebdc3f6a2a9493440fc66cc080a80a74ecaa7439..8198cc84b4cd4ad854f72ef25c0b82c2a6ced964 100644 (file)
@@ -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)
+)