From patchwork Mon Jan 31 10:42:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 41 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:25 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.5 with SMTP id b5cs80629yan; Mon, 31 Jan 2011 02:42:32 -0800 (PST) Received: by 10.216.7.8 with SMTP id 8mr11521826weo.30.1296470551642; Mon, 31 Jan 2011 02:42:31 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id u29si34243306wei.132.2011.01.31.02.42.29 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 31 Jan 2011 02:42:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.69) (envelope-from ) id 1PjrDG-0004IL-JT; Mon, 31 Jan 2011 10:42:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Blue Swirl Subject: [PATCH] hw/slavio_intctl.c: fix gcc warning about array bounds overrun Date: Mon, 31 Jan 2011 10:42:26 +0000 Message-Id: <1296470546-16488-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.1 The Ubuntu 10.10 gcc for ARM complains that we might be overrunning the cpu_irqs[][] array: silence this by correcting the bounds on the loop. (In fact we would not have overrun the array because bit MAX_PILS in pil_pending and irl_out will always be 0.) Also add a comment about why the loop's lower bound is OK. Signed-off-by: Peter Maydell --- I've tested that with this change we still boot the sparc Debian image from http://people.debian.org/~aurel32/qemu/sparc/ and the change makes sense according to my understanding of http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt hw/slavio_intctl.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/hw/slavio_intctl.c b/hw/slavio_intctl.c index fd69354..a83e5b8 100644 --- a/hw/slavio_intctl.c +++ b/hw/slavio_intctl.c @@ -289,7 +289,12 @@ static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs) pil_pending |= (s->slaves[i].intreg_pending & CPU_SOFTIRQ_MASK) >> 16; if (set_irqs) { - for (j = MAX_PILS; j > 0; j--) { + /* Since there is not really an interrupt 0 (and pil_pending + * and irl_out bit zero are thus always zero) there is no need + * to do anything with cpu_irqs[i][0] and it is OK not to do + * the j=0 iteration of this loop. + */ + for (j = MAX_PILS-1; j > 0; j--) { if (pil_pending & (1 << j)) { if (!(s->slaves[i].irl_out & (1 << j))) { qemu_irq_raise(s->cpu_irqs[i][j]);