From patchwork Tue Jan 13 19:04:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 428599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id DC3ED1401F0; Wed, 14 Jan 2015 06:07:03 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YB6nu-000278-6m; Tue, 13 Jan 2015 19:07:02 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YB6n2-0001sQ-89 for fwts-devel@lists.ubuntu.com; Tue, 13 Jan 2015 19:06:08 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginm.net ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1YB6n2-0004GC-5A for fwts-devel@lists.ubuntu.com; Tue, 13 Jan 2015 19:06:08 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 07/46] utilities: kernelscan: reduce scope of variables Date: Tue, 13 Jan 2015 19:04:26 +0000 Message-Id: <1421175905-17035-8-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421175905-17035-1-git-send-email-colin.king@canonical.com> References: <1421175905-17035-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King cppcheck is picking up some minor style issues which can be easily fixed: [src/utilities/kernelscan.c:125]: (style) The scope of the variable 'ch' can be reduced. [src/utilities/kernelscan.c:437]: (style) The scope of the variable 'nextch1' can be reduced. [src/utilities/kernelscan.c:437]: (style) The scope of the variable 'nextch2' can be reduced. [src/utilities/kernelscan.c:552]: (style) The scope of the variable 'ch' can be reduced. [src/utilities/kernelscan.c:640]: (style) The scope of the variable 'ch' can be reduced. [src/utilities/kernelscan.c:783]: (style) The scope of the variable 'ret' can be reduced. Signed-off-by: Colin Ian King Acked-by: Ivan Hu Acked-by: Keng-Yu Lin --- src/utilities/kernelscan.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c index 0eeeb95..f0f5e82 100644 --- a/src/utilities/kernelscan.c +++ b/src/utilities/kernelscan.c @@ -122,15 +122,13 @@ static void parser_new(parser *p, FILE *fp, bool skip_white_space) */ static int get_next(parser *p) { - int ch; - /* * If we have chars pushed using unget_next * then pop them off the list first */ if (p->get_chars) { get_stack *tmp = p->get_chars; - ch = tmp->ch; + int ch = tmp->ch; p->get_chars = tmp->next; free(tmp); @@ -434,7 +432,6 @@ static int skip_comments(parser *p) */ static int parse_number(parser *p, token *t, int ch) { - int nextch1, nextch2; bool ishex = false; bool isoct = false; @@ -442,6 +439,8 @@ static int parse_number(parser *p, token *t, int ch) * Crude way to detect the kind of integer */ if (ch == '0') { + int nextch1, nextch2; + token_append(t, ch); nextch1 = get_next(p); @@ -549,14 +548,13 @@ static int parse_identifier(parser *p, token *t, int ch) static int parse_literal(parser *p, token *t, int literal, token_type type) { bool escaped = false; - int ch; t->type = type; token_append(t, literal); for (;;) { - ch = get_next(p); + int ch = get_next(p); if (ch == EOF) { return PARSER_OK; } @@ -637,11 +635,10 @@ static int parse_minus(parser *p, token *t, int op) */ static int get_token(parser *p, token *t) { - int ch; int ret; for (;;) { - ch = get_next(p); + int ch = get_next(p); switch (ch) { case EOF: @@ -780,7 +777,6 @@ static char *strdupcat(char *old, char *new) */ static int parse_kernel_message(parser *p, token *t) { - int ret; bool got_string = false; bool emit = false; bool found = false; @@ -802,7 +798,7 @@ static int parse_kernel_message(parser *p, token *t) token_clear(t); for (;;) { - ret = get_token(p, t); + int ret = get_token(p, t); if (ret == EOF) { free(line); return EOF;