semantic patch using coccinelle

commandline session

$ 4.2.36 26 525---> cat source.c
 #include 

int
main(int argc, char *argv[])
    {
            unsigned int bytes = 1024 * 1024;
            char *buf;

            /* allocate memory */
            buf = alloca(bytes);

            return 0;
    }
$ 4.2.36 27 526---> cat source.cocci
@@ expression E; @@

-alloca(E)
+malloc(E)
$ 4.2.36 28 527---> spatch --sp-file source.cocci source.c
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: source.c
diff =
--- source.c
+++ /tmp/cocci-output-9888-dc7b02-source.c
@@ -7,7 +7,7 @@ main(int argc, char *argv[])
             char *buf;

             /* allocate memory */
-            buf = alloca(bytes);
+            buf = malloc(bytes);

             return 0;
     }
$ 4.2.36 29 528---> spatch --sp-file source.cocci source.c -o newsource.c
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: source.c
diff =
--- source.c
+++ /tmp/cocci-output-9896-231c5d-source.c
@@ -7,7 +7,7 @@ main(int argc, char *argv[])
             char *buf;

             /* allocate memory */
-            buf = alloca(bytes);
+            buf = malloc(bytes);

             return 0;
     }
$ 4.2.36 30 529--->

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s