From patchwork Tue Jan 13 19:04:54 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: 428615 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 686FB1401EB; Wed, 14 Jan 2015 06:08:12 +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 1YB6p1-0002J2-5r; Tue, 13 Jan 2015 19:08:11 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YB6nD-0001vt-3M for fwts-devel@lists.ubuntu.com; Tue, 13 Jan 2015 19:06:19 +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 1YB6nD-0004Hv-0h for fwts-devel@lists.ubuntu.com; Tue, 13 Jan 2015 19:06:19 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 35/46] lib: fwts_log: reduce scope of variables Date: Tue, 13 Jan 2015 19:04:54 +0000 Message-Id: <1421175905-17035-36-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/lib/src/fwts_log.c:205]: (style) The scope of the variable 'str' can be reduced. [src/lib/src/fwts_log.c:280]: (style) The scope of the variable 'token' can be reduced. [src/lib/src/fwts_log.c:339]: (style) The scope of the variable 'trunc_len' can be reduced. [src/lib/src/fwts_log.c:411]: (style) The scope of the variable 'buffer' can be reduced. Signed-off-by: Colin Ian King Acked-by: Ivan Hu Acked-by: Alex Hung --- src/lib/src/fwts_log.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c index 7eeda68..1cfdcba 100644 --- a/src/lib/src/fwts_log.c +++ b/src/lib/src/fwts_log.c @@ -202,11 +202,10 @@ char *fwts_log_level_to_str(const fwts_log_level level) void fwts_log_print_fields(void) { fwts_log_field field = 1; - char *str; printf("Available fields: "); for (field=1; ; field <<= 1) { - str = fwts_log_field_to_str(field); + char *str = fwts_log_field_to_str(field); if (strcmp(str, LOG_UNKOWN_FIELD) == 0) break; printf("%s%s", field == 1 ? "" : ",", str); @@ -277,11 +276,12 @@ void fwts_log_filter_unset_field(const fwts_log_field filter) */ void fwts_log_set_field_filter(const char *str) { - char *token; char *saveptr; fwts_log_field field; for (;; str=NULL) { + char *token; + if ((token = strtok_r((char*)str, ",|", &saveptr)) == NULL) break; if (*token == '^' || *token == '~') { @@ -336,7 +336,6 @@ static char *fwts_log_filename(const char *filename, const fwts_log_type type) char *new_name; char *suffix; size_t suffix_len; - size_t trunc_len; size_t filename_len; struct stat stat_buf; @@ -366,8 +365,8 @@ static char *fwts_log_filename(const char *filename, const fwts_log_type type) !strcmp(ptr, ".json") || !strcmp(ptr, ".xml") || !strcmp(ptr, ".html"))) { + size_t trunc_len = ptr - filename; - trunc_len = ptr - filename; if ((new_name = calloc(trunc_len + suffix_len + 1, 1)) == NULL) { fprintf(stderr, "Cannot allocate log name.\n"); return NULL; @@ -408,13 +407,12 @@ int fwts_log_printf(fwts_log *log, va_list args; int ret = 0; - char buffer[LOG_MAX_BUF_SIZE]; - if (!((field & LOG_FIELD_MASK) & fwts_log_filter)) return ret; if (log && log->magic == LOG_MAGIC) { fwts_list_link *item; + char buffer[LOG_MAX_BUF_SIZE]; /* * With the possibility of having multiple logs being written