Skip to content

Commit 9ca356f

Browse files
rscharfegitster
authored andcommitted
coccinelle: remove parentheses that become unnecessary
Transformations that hide multiplications can end up with an pair of parentheses that is no longer needed. E.g. with a rule like this: @@ expression E; @@ - E * 2 + double(E) ... we might get a patch like this: - x = (a + b) * 2; + x = double((a + b)); Add a pair of parentheses to the preimage side of such rules. Coccinelle will generate patches that remove them if they are present, and it will still match expressions that lack them. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4010f1d commit 9ca356f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contrib/coccinelle/array.cocci

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ T *dst;
44
T *src;
55
expression n;
66
@@
7-
- memcpy(dst, src, n * sizeof(*dst));
7+
- memcpy(dst, src, (n) * sizeof(*dst));
88
+ COPY_ARRAY(dst, src, n);
99

1010
@@
@@ -13,7 +13,7 @@ T *dst;
1313
T *src;
1414
expression n;
1515
@@
16-
- memcpy(dst, src, n * sizeof(*src));
16+
- memcpy(dst, src, (n) * sizeof(*src));
1717
+ COPY_ARRAY(dst, src, n);
1818

1919
@@
@@ -22,7 +22,7 @@ T *dst;
2222
T *src;
2323
expression n;
2424
@@
25-
- memcpy(dst, src, n * sizeof(T));
25+
- memcpy(dst, src, (n) * sizeof(T));
2626
+ COPY_ARRAY(dst, src, n);
2727

2828
@@
@@ -47,13 +47,13 @@ type T;
4747
T *ptr;
4848
expression n;
4949
@@
50-
- ptr = xmalloc(n * sizeof(*ptr));
50+
- ptr = xmalloc((n) * sizeof(*ptr));
5151
+ ALLOC_ARRAY(ptr, n);
5252

5353
@@
5454
type T;
5555
T *ptr;
5656
expression n;
5757
@@
58-
- ptr = xmalloc(n * sizeof(T));
58+
- ptr = xmalloc((n) * sizeof(T));
5959
+ ALLOC_ARRAY(ptr, n);

0 commit comments

Comments
 (0)