From patchwork Wed Oct 19 13:26:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 684112 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 3szXm72Nrhz9t0w; Thu, 20 Oct 2016 00:27: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 1bwqtZ-000126-DB; Wed, 19 Oct 2016 13:27:01 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1bwqtI-0000yI-GO for fwts-devel@lists.ubuntu.com; Wed, 19 Oct 2016 13:26:44 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1bwqtI-0007pe-5G; Wed, 19 Oct 2016 13:26:44 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 7/7] dmi: dmicheck: fix a couple of cppcheck style warnings Date: Wed, 19 Oct 2016 14:26:39 +0100 Message-Id: <20161019132639.16524-8-colin.king@canonical.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161019132639.16524-1-colin.king@canonical.com> References: <20161019132639.16524-1-colin.king@canonical.com> MIME-Version: 1.0 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: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King reduce the scope of some local variables. Do not initialize struct_type = 0 as it gets set a little while later. Change the while (1) loop to the fwts for (;;) idoim. Cleans up cppcheck style warnings: src/dmi/dmicheck/dmicheck.c:452]: (style) The scope of the variable 'dmi_entry_length' can be reduced. src/dmi/dmicheck/dmicheck.c:599]: (style) The scope of the variable 'struct_length' can be reduced. src/dmi/dmicheck/dmicheck.c:600]: (style) The scope of the variable 'struct_type' can be reduced. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/dmi/dmicheck/dmicheck.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c index 51ccd26..1934ebe 100644 --- a/src/dmi/dmicheck/dmicheck.c +++ b/src/dmi/dmicheck/dmicheck.c @@ -449,7 +449,6 @@ static void dmi_dump_entry30(fwts_framework *fw, fwts_smbios30_entry *entry) static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry) { uint8_t *table, *ptr; - uint8_t dmi_entry_length; uint8_t dmi_entry_type = 0; uint16_t i = 0; uint16_t table_length = entry->struct_table_length; @@ -460,6 +459,8 @@ static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry) return FWTS_ERROR; for (i = 0; i < entry->number_smbios_structures; i++) { + uint8_t dmi_entry_length; + if (ptr > table + table_length) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "SMBIOSTableLengthTooSmall", @@ -596,8 +597,6 @@ static int smbios_entry_check(fwts_framework *fw) static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry) { uint8_t *table, *ptr; - uint8_t struct_length; - uint8_t struct_type = 0; uint16_t i = 0; uint32_t table_length = entry->struct_table_max_size; int ret = FWTS_OK; @@ -606,8 +605,10 @@ static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry) if (table == NULL) return FWTS_ERROR; - while (1) - { + for (;;) { + uint8_t struct_length; + uint8_t struct_type; + if (ptr > table + table_length) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "SMBIOS30TableLengthTooSmall",