aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-09 11:24:51 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-09 11:24:51 +0100
commit5a0ffe77fd777c069edea3b75f88b6baf6a4e6f1 (patch)
tree6889f0ae278a10df00a290ad220e0417b8fac8d9 /sam.c
parent5ef02c4cb448d5d241971da46f702e8b994d955b (diff)
downloadvis-5a0ffe77fd777c069edea3b75f88b6baf6a4e6f1.tar.gz
vis-5a0ffe77fd777c069edea3b75f88b6baf6a4e6f1.tar.xz
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
Diffstat (limited to 'sam.c')
-rw-r--r--sam.c3
1 files changed, 2 insertions, 1 deletions
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) {