git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] coccinelle: remove parentheses that become unnecessary
@ 2017-10-01 15:12 René Scharfe
  2017-10-01 15:14 ` [PATCH 2/2] run-command: use ALLOC_ARRAY René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-10-01 15:12 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] run-command: use ALLOC_ARRAY
  2017-10-01 15:12 [PATCH 1/2] coccinelle: remove parentheses that become unnecessary René Scharfe
@ 2017-10-01 15:14 ` René Scharfe
  2017-10-02 19:20   ` Stefan Beller
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-10-01 15:14 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Use the macro ALLOC_ARRAY to allocate an array.  This is shorter and
eaasier, as it automatically infers the size of elements.

Patch generated with Coccinelle and contrib/coccinelle/array.cocci.

Signeg-off-by: Rene Scharfe <l.s.r@web.de>
---
 run-command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/run-command.c b/run-command.c
index b5e6eb37c0..014b2165b5 100644
--- a/run-command.c
+++ b/run-command.c
@@ -452,7 +452,7 @@ static char **prep_childenv(const char *const *deltaenv)
 	}
 
 	/* Create an array of 'char *' to be used as the childenv */
-	childenv = xmalloc((env.nr + 1) * sizeof(char *));
+	ALLOC_ARRAY(childenv, env.nr + 1);
 	for (i = 0; i < env.nr; i++)
 		childenv[i] = env.items[i].util;
 	childenv[env.nr] = NULL;
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] run-command: use ALLOC_ARRAY
  2017-10-01 15:14 ` [PATCH 2/2] run-command: use ALLOC_ARRAY René Scharfe
@ 2017-10-02 19:20   ` Stefan Beller
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Beller @ 2017-10-02 19:20 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Sun, Oct 1, 2017 at 8:14 AM, René Scharfe <l.s.r@web.de> wrote:
> Use the macro ALLOC_ARRAY to allocate an array.  This is shorter and
> eaasier, as it automatically infers the size of elements.

easier

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-02 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-01 15:12 [PATCH 1/2] coccinelle: remove parentheses that become unnecessary René Scharfe
2017-10-01 15:14 ` [PATCH 2/2] run-command: use ALLOC_ARRAY René Scharfe
2017-10-02 19:20   ` Stefan Beller

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).