From patchwork Fri Mar 15 11:26:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 227957 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 8AF022C0089 for ; Fri, 15 Mar 2013 22:26:30 +1100 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UGSmJ-0001yF-9y; Fri, 15 Mar 2013 11:26:27 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UGSmI-0001y3-6y for fwts-devel@lists.ubuntu.com; Fri, 15 Mar 2013 11:26:26 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1UGSmI-0004Kp-4f for fwts-devel@lists.ubuntu.com; Fri, 15 Mar 2013 11:26:26 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] uefi: uefivariable: fix build error on older compilers Date: Fri, 15 Mar 2013 11:26:25 +0000 Message-Id: <1363346785-25119-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.1.2 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 Curiously, we are getting the following error on older versions of GCC: cc1: warnings being treated as errors uefi/uefirtvariable/uefirtvariable.c: In function 'getnextvariable_test2': uefi/uefirtvariable/uefirtvariable.c:352:5: error: array subscript is above array bounds ..and it only happens on 32 bit builds. Looking at the compiled object code, it seems that: c = variablename[(len / sizeof(c)) - 1]; produces an add of 0xffffffff todo the subtraction of -1 which triggers the array subscript array bounds warning, where as: uint64_t i = (len / sizeof(c)) - 1; c = variablename[i]; produces a subtraction of 1 and everthing is fine. This patch is a workaround. I've hand checked the result, and it produces the code we require, so I think the original code was OK but GCC was being overly zealous. Signed-off-by: Colin Ian King Acked-by: Ivan Hu Acked-by: Alex Hung --- src/uefi/uefirtvariable/uefirtvariable.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c index 7242afd..c5caa33 100644 --- a/src/uefi/uefirtvariable/uefirtvariable.c +++ b/src/uefi/uefirtvariable/uefirtvariable.c @@ -349,7 +349,9 @@ static bool strlen_valid(uint16_t *variablename, uint64_t variablenamesize) uint16_t c; for (len = 2; len <= variablenamesize; len += sizeof(c)) { - c = variablename[(len / sizeof(c)) - 1]; + uint64_t i = (len / sizeof(c)) - 1; + + c = variablename[i]; if (!c) break; }