Indentation when adding an if
Hi,
Consider the following C code and cocci patch:
#include <stdio.h>
int x;
int main(int argc, char **argv)
{
if (y)
do_something(x);
}@@
identifier x;
@@
- do_something(x);
+ if (x)
+ do_one_thing();
+ else
+ do_another_thing();
For this input, spatch produces the following output:
$ spatch --sp-file test.cocci test.c
init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: test.c
diff =
--- test.c
+++ /tmp/cocci-output-18011-a28e99-test.c
@@ -5,5 +5,8 @@ int x;
int main(int argc, char **argv)
{
if (y)
- do_something(x);
+ if (x)
+ do_one_thing();
+ else
+ do_another_thing();
}Obviously it gets the indentation wrong there. Is this a bug?
Adding curly braces around the outer if (in the C code) yields the correct indentation, while adding the braces around the inner if (in the cocci patch) does not.
Adding an else branch to the outer if also produces the wrong indentation.
--
Regards,
Christoph
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 46 lines · Christoph Böhmwalder
Hi,
Consider the following C code and cocci patch:
#include <
stdio.h>int x;
int
main(int argc, char **argv){ if (y) do_something(x); }@@
identifier x;
@@
-do_something(x);
+ if (x)(quoted diff) +3
-0+ do_one_thing(); + else + do_another_thing();For this input, spatch produces the following output:
$ spatch --sp-file test.cocci test.c init_defs_builtins: /usr/lib/coccinelle/standard.h HANDLING: test.c diff =tmp/cocci-output-18011-a28e99-test.c renamed from test.c +4
-1@@ -5,5 +5,8 @@ int x;int main (int argc,char **argv) {if (y) -do_something (x); +if (x) +do_one_thing (); +else +do_another_thing (); }
Quoted 7 lines
Obviously it gets the indentation wrong there. Is this a bug?
Adding curly braces around the outer if (in the C code) yields the correct indentation, while adding the braces around the inner if (in the cocci patch) does not.
Adding an else branch to the outer if also produces the wrong indentation.
This is surely a bug. Thank you for the report.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci