From: Olaf Hering Subject: [PATCH 1/3] mini-os: tpm: fix array access in locality_enabled Date: Tue, 22 Jul 2014 09:19:15 +0200 Message-ID: <1406013557-11699-2-git-send-email-olaf@aepfle.de> References: <1406013557-11699-1-git-send-email-olaf@aepfle.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1406013557-11699-1-git-send-email-olaf@aepfle.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Daniel De Graaf , Stefano Stabellini , Samuel Thibault Cc: Olaf Hering , Ian Campbell , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org gcc-4.3 fails to prove that array indices will remain positive. Add a hint for the compiler and check the index value before using it. Signed-off-by: Olaf Hering --- extras/mini-os/tpm_tis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/mini-os/tpm_tis.c b/extras/mini-os/tpm_tis.c index e8ca69f..dc4134a 100644 --- a/extras/mini-os/tpm_tis.c +++ b/extras/mini-os/tpm_tis.c @@ -611,7 +611,7 @@ s_time_t tpm_calc_ordinal_duration(struct tpm_chip *chip, static int locality_enabled(struct tpm_chip* tpm, int l) { - return tpm->enabled_localities & (1 << l); + return l >= 0 && tpm->enabled_localities & (1 << l); } static int check_locality(struct tpm_chip* tpm, int l) {