{"thread":{"id":"46873","subject":"[PATCH 1/2] coccinelle: remove parentheses that become unnecessary","startedAt":"2017-10-01T15:12:18Z","lastAt":"2017-10-02T19:20:34Z","messageCount":3,"participants":["René Scharfe","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"329301","messageId":"c4abb7ac-dafd-57f2-8b46-45d610d656c4@web.de","threadId":"46873","inReplyTo":null,"subject":"[PATCH 1/2] coccinelle: remove parentheses that become unnecessary","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-10-01T15:12:08Z","receivedAt":"2017-10-01T15:12:18Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Transformations that hide multiplications can end up with an pair of\nparentheses that is no longer needed.  E.g. with a rule like this:\n\n  @@\n  expression E;\n  @@\n  - E * 2\n  + double(E)\n\n... we might get a patch like this:\n\n  -\tx = (a + b) * 2;\n  +\tx = double((a + b));\n\nAdd a pair of parentheses to the preimage side of such rules.\nCoccinelle will generate patches that remove them if they are present,\nand it will still match expressions that lack them.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n contrib/coccinelle/array.cocci | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci\nindex c61d1ca8dc..01586821dc 100644\n--- a/contrib/coccinelle/array.cocci\n+++ b/contrib/coccinelle/array.cocci\n@@ -4,7 +4,7 @@ T *dst;\n T *src;\n expression n;\n @@\n-- memcpy(dst, src, n * sizeof(*dst));\n+- memcpy(dst, src, (n) * sizeof(*dst));\n + COPY_ARRAY(dst, src, n);\n \n @@\n@@ -13,7 +13,7 @@ T *dst;\n T *src;\n expression n;\n @@\n-- memcpy(dst, src, n * sizeof(*src));\n+- memcpy(dst, src, (n) * sizeof(*src));\n + COPY_ARRAY(dst, src, n);\n \n @@\n@@ -22,7 +22,7 @@ T *dst;\n T *src;\n expression n;\n @@\n-- memcpy(dst, src, n * sizeof(T));\n+- memcpy(dst, src, (n) * sizeof(T));\n + COPY_ARRAY(dst, src, n);\n \n @@\n@@ -47,7 +47,7 @@ type T;\n T *ptr;\n expression n;\n @@\n-- ptr = xmalloc(n * sizeof(*ptr));\n+- ptr = xmalloc((n) * sizeof(*ptr));\n + ALLOC_ARRAY(ptr, n);\n \n @@\n@@ -55,5 +55,5 @@ type T;\n T *ptr;\n expression n;\n @@\n-- ptr = xmalloc(n * sizeof(T));\n+- ptr = xmalloc((n) * sizeof(T));\n + ALLOC_ARRAY(ptr, n);\n-- \n2.14.2\n"},{"id":"329302","messageId":"6343155c-0986-06b0-8ced-146b23b8a137@web.de","threadId":"46873","inReplyTo":"c4abb7ac-dafd-57f2-8b46-45d610d656c4@web.de","subject":"[PATCH 2/2] run-command: use ALLOC_ARRAY","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-10-01T15:14:31Z","receivedAt":"2017-10-01T15:14:40Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use the macro ALLOC_ARRAY to allocate an array.  This is shorter and\neaasier, as it automatically infers the size of elements.\n\nPatch generated with Coccinelle and contrib/coccinelle/array.cocci.\n\nSigneg-off-by: Rene Scharfe <l.s.r@web.de>\n---\n run-command.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/run-command.c b/run-command.c\nindex b5e6eb37c0..014b2165b5 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -452,7 +452,7 @@ static char **prep_childenv(const char *const *deltaenv)\n \t}\n \n \t/* Create an array of 'char *' to be used as the childenv */\n-\tchildenv = xmalloc((env.nr + 1) * sizeof(char *));\n+\tALLOC_ARRAY(childenv, env.nr + 1);\n \tfor (i = 0; i < env.nr; i++)\n \t\tchildenv[i] = env.items[i].util;\n \tchildenv[env.nr] = NULL;\n-- \n2.14.2\n"},{"id":"329474","messageId":"CAGZ79kazU=JEnAAdzf-oGOMBDQaFZabxJzFOTYmhFLssrvY=BA@mail.gmail.com","threadId":"46873","inReplyTo":"6343155c-0986-06b0-8ced-146b23b8a137@web.de","subject":"Re: [PATCH 2/2] run-command: use ALLOC_ARRAY","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-10-02T19:20:28Z","receivedAt":"2017-10-02T19:20:34Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sun, Oct 1, 2017 at 8:14 AM, René Scharfe <l.s.r@web.de> wrote:\n> Use the macro ALLOC_ARRAY to allocate an array.  This is shorter and\n> eaasier, as it automatically infers the size of elements.\n\neasier\n\nThanks,\nStefan\n"}]}