From patchwork Wed Apr 13 14:24:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Pokorn=C3=BD?= X-Patchwork-Id: 703801 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3DEPaxa003357 for ; Wed, 13 Apr 2011 14:25:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756203Ab1DMOZe (ORCPT ); Wed, 13 Apr 2011 10:25:34 -0400 Received: from fep32.mx.upcmail.net ([62.179.121.50]:37179 "EHLO fep32.mx.upcmail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756198Ab1DMOZe (ORCPT ); Wed, 13 Apr 2011 10:25:34 -0400 Received: from edge05.upcmail.net ([192.168.13.212]) by viefep16-int.chello.at (InterMail vM.8.01.02.02 201-2260-120-106-20100312) with ESMTP id <20110413142436.XVOG9043.viefep16-int.chello.at@edge05.upcmail.net>; Wed, 13 Apr 2011 16:24:36 +0200 Received: from [192.168.42.128] ([94.112.231.238]) by edge05.upcmail.net with edge id X2Qa1g00T59GDcW052Qb1t; Wed, 13 Apr 2011 16:24:36 +0200 X-SourceIP: 94.112.231.238 Message-ID: <4DA5B222.2080501@seznam.cz> Date: Wed, 13 Apr 2011 16:24:34 +0200 From: =?ISO-8859-1?Q?Jan_Pokorn=FD?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: sparse@chrisli.org CC: linux-sparse@vger.kernel.org Subject: [PATCH] use ARRAY_SIZE() when possible (continued) X-Enigmail-Version: 1.1.1 X-Cloudmark-Analysis: v=1.1 cv=zlRBWuFCZaNL9+WHNm1pWLowY5Lx061w2zJBJiDkNAU= c=1 sm=0 a=gr3JKtqGReIA:10 a=6OF-3uXUpzMA:10 a=8nJEP1OIZ-IA:10 a=YgwN3AOMAAAA:8 a=RtNFKoFjTdxG4cfgMOEA:9 a=I3gekcXAvH8mBe8RyIYA:7 a=wPNLvfGTeEIA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 13 Apr 2011 14:25:36 +0000 (UTC) Some cases were omitted with the patch from Namhyung Kim (commit c5e425e in Chris Li's repo). My curiosity led me to try out coccinelle/spatch as suggested by Nicholas Mc Guire in reply to Kim's patch, but it*) only discovered occurrences in show-parse.c, probably because of "const vs. non-const" differences of array item types and the expression given to sizeof. *) sequence to try coccinelle out on this case (when coccinelle installed): $ wget http://coccinelle.lip6.fr/rules/array.cocci $ sed 's//"lib.h"/' array.cocci > array-sparse.cocci $ for i in $(find . -path ./validation -prune -o -name "*.c" -print); \ > do spatch -sp_file array-sparse.cocci $i; done Beside proceeding messages, this will print out any "real" patch generated according to the semantic patch in `array-sparse.cocci' (it can also reflect these changes directly etc.). Signed-off-by: Jan Pokorny --- expression.c | 2 +- linearize.c | 2 +- show-parse.c | 4 ++-- sparse.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/expression.c b/expression.c index 7e06e60..d9cdfd3 100644 --- a/expression.c +++ b/expression.c @@ -916,7 +916,7 @@ struct token *assignment_expression(struct token *token, struct expression **tre SPECIAL_SHR_ASSIGN, SPECIAL_AND_ASSIGN, SPECIAL_OR_ASSIGN, SPECIAL_XOR_ASSIGN }; int i, op = token->special; - for (i = 0; i < sizeof(assignments)/sizeof(int); i++) + for (i = 0; i < ARRAY_SIZE(assignments); i++) if (assignments[i] == op) { struct expression * expr = alloc_expression(token->pos, EXPR_ASSIGNMENT); expr->left = *tree; diff --git a/linearize.c b/linearize.c index 5819862..6f3fa40 100644 --- a/linearize.c +++ b/linearize.c @@ -282,7 +282,7 @@ const char *show_instruction(struct instruction *insn) if (!insn->bb) buf += sprintf(buf, "# "); - if (opcode < sizeof(opcodes)/sizeof(char *)) { + if (opcode < ARRAY_SIZE(opcodes)) { const char *op = opcodes[opcode]; if (!op) buf += sprintf(buf, "opcode:%d", opcode); diff --git a/show-parse.c b/show-parse.c index 73cc86a..a5beafe 100644 --- a/show-parse.c +++ b/show-parse.c @@ -754,7 +754,7 @@ static int show_binop(struct expression *expr) unsigned int op = expr->op; opname = show_special(op); - if (op < sizeof(name)/sizeof(*name)) + if (op < ARRAY_SIZE(name)) opname = name[op]; printf("\t%s.%d\t\tv%d,v%d,v%d\n", opname, expr->ctype->bit_size, @@ -782,7 +782,7 @@ static int show_regular_preop(struct expression *expr) const char *opname; opname = show_special(op); - if (op < sizeof(name)/sizeof(*name)) + if (op < ARRAY_SIZE(name)) opname = name[op]; printf("\t%s.%d\t\tv%d,v%d\n", opname, expr->ctype->bit_size, new, target); return new; diff --git a/sparse.c b/sparse.c index 4026ba7..67b7d9e 100644 --- a/sparse.c +++ b/sparse.c @@ -187,7 +187,7 @@ static void check_call_instruction(struct instruction *insn) ident = fn->sym->ident; if (!ident) return; - for (i = 0; i < sizeof(check_fn)/sizeof(struct checkfn) ; i++) { + for (i = 0; i < ARRAY_SIZE(check_fn); i++) { if (check_fn[i].id != ident) continue; check_fn[i].check(insn);