From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3lWr-0004Uv-P3 for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:22:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3lWn-00015M-Ms for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:22:17 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:59016 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3lWn-000156-Fj for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:22:13 -0400 From: Peter Maydell Date: Mon, 29 Jul 2013 12:22:11 +0100 Message-Id: <1375096931-13842-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH for-1.6?] tpm.c: Don't try to put -1 in a variable of type TpmModel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Stefan Berger , patches@linaro.org The TpmModel type is an enum (valid values 0 and 1), which means the compiler can legitimately decide that comparisons like 'tpm_models[i] == -1' are never true. (For example it could pick 'unsigned char' as its type for representing the enum.) Avoid this issue by using TPM_MODEL_MAX to mark entries in the tpm_models[] array which aren't filled in, instead of -1. This silences a clang warning: tpm.c:43:27: error: comparison of constant -1 with expression of type 'enum TpmModel' is always false [-Werror,-Wtautological-constant-out-of-range-compare] if (tpm_models[i] == -1) { ~~~~~~~~~~~~~ ^ ~~ Signed-off-by: Peter Maydell --- Disclaimer: I have compiled this, and it's a pretty safe looking change, but I haven't tested it... tpm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tpm.c b/tpm.c index f13c9bc..d68d69f 100644 --- a/tpm.c +++ b/tpm.c @@ -32,7 +32,7 @@ static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = { }; static enum TpmModel tpm_models[TPM_MAX_MODELS] = { - -1, + TPM_MODEL_MAX, }; int tpm_register_model(enum TpmModel model) @@ -40,7 +40,7 @@ int tpm_register_model(enum TpmModel model) int i; for (i = 0; i < TPM_MAX_MODELS; i++) { - if (tpm_models[i] == -1) { + if (tpm_models[i] == TPM_MODEL_MAX) { tpm_models[i] = model; return 0; } -- 1.7.9.5