[Cocci] moving const instead of not matching?

Johannes Berg johannes at sipsolutions.net
Tue Sep 18 11:20:33 CEST 2018


I was trying to do something like this:

@@
typedef u8;
expression D, T, S2;
@@
(
 memcpy(
-(u8 *)(D)
+D
 ,
-(u8 *)(T)
+T
 , S2)
|
 memcpy(
-(u8 *)(D)
+D
 ,
-(T)
+T
 , S2)
|
 memcpy(
-(D)
+D
 ,
-(u8 *)(T)
+T
 , S2)
)


but then I ran across a place that had a const, and the result was
rather unexpected:

$ spatch --sp-file /tmp/test3.spatch /tmp/test.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: /tmp/test.c
diff = 
--- /tmp/test.c
+++ /tmp/cocci-output-8879-8411db-test.c
@@ -1,4 +1,4 @@
 int main()
 {
-	memcpy(dst, (const u8 *)src, sz);
+	memcpy(dst, src const, sz);
 }


Why is the const being moved there, rather than not matching?

spatch version 1.0.6.

johannes


More information about the Cocci mailing list