From 5a0ffe77fd777c069edea3b75f88b6baf6a4e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 9 Feb 2017 11:24:51 +0100 Subject: sam: fix bogus clang compiler warning Strictly speaking this is a compiler bug: https://llvm.org/bugs/show_bug.cgi?id=22062 The C11 standard section 6.4.4.3 says: "An identifier declared as an enumeration constant has type int." and 6.7.2.2: "Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration." So while `err` can store a value larger than that of any enumeration member, it could also be of signed type, resulting in a warning about comparing integers of different signs. Converting it to size_t before the range check and array indexing, should fix both warnings. Fix #478 --- sam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sam.c b/sam.c index e123b56..00b5e1a 100644 --- a/sam.c +++ b/sam.c @@ -431,7 +431,8 @@ const char *sam_error(enum SamError err) { [SAM_ERR_GROUP_INVALID_CMD] = "Destructive command in group", }; - return err < LENGTH(error_msg) ? error_msg[err] : NULL; + size_t idx = err; + return idx < LENGTH(error_msg) ? error_msg[idx] : NULL; } static void change_free(Change *c) { -- cgit v1.2.3