git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/2] coccinelle: remove parentheses that become unnecessary
Date: Sun, 1 Oct 2017 17:12:08 +0200	[thread overview]
Message-ID: <c4abb7ac-dafd-57f2-8b46-45d610d656c4@web.de> (raw)

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 <l.s.r@web.de>
---
 contrib/coccinelle/array.cocci | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci
index c61d1ca8dc..01586821dc 100644
--- a/contrib/coccinelle/array.cocci
+++ b/contrib/coccinelle/array.cocci
@@ -4,7 +4,7 @@ T *dst;
 T *src;
 expression n;
 @@
-- memcpy(dst, src, n * sizeof(*dst));
+- memcpy(dst, src, (n) * sizeof(*dst));
 + COPY_ARRAY(dst, src, n);
 
 @@
@@ -13,7 +13,7 @@ T *dst;
 T *src;
 expression n;
 @@
-- memcpy(dst, src, n * sizeof(*src));
+- memcpy(dst, src, (n) * sizeof(*src));
 + COPY_ARRAY(dst, src, n);
 
 @@
@@ -22,7 +22,7 @@ T *dst;
 T *src;
 expression n;
 @@
-- memcpy(dst, src, n * sizeof(T));
+- memcpy(dst, src, (n) * sizeof(T));
 + COPY_ARRAY(dst, src, n);
 
 @@
@@ -47,7 +47,7 @@ type T;
 T *ptr;
 expression n;
 @@
-- ptr = xmalloc(n * sizeof(*ptr));
+- ptr = xmalloc((n) * sizeof(*ptr));
 + ALLOC_ARRAY(ptr, n);
 
 @@
@@ -55,5 +55,5 @@ type T;
 T *ptr;
 expression n;
 @@
-- ptr = xmalloc(n * sizeof(T));
+- ptr = xmalloc((n) * sizeof(T));
 + ALLOC_ARRAY(ptr, n);
-- 
2.14.2

             reply	other threads:[~2017-10-01 15:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-01 15:12 René Scharfe [this message]
2017-10-01 15:14 ` [PATCH 2/2] run-command: use ALLOC_ARRAY René Scharfe
2017-10-02 19:20   ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4abb7ac-dafd-57f2-8b46-45d610d656c4@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).