diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-02-09 11:24:51 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-02-09 11:24:51 +0100 |
| commit | 5a0ffe77fd777c069edea3b75f88b6baf6a4e6f1 (patch) | |
| tree | 6889f0ae278a10df00a290ad220e0417b8fac8d9 | |
| parent | 5ef02c4cb448d5d241971da46f702e8b994d955b (diff) | |
| download | vis-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
| -rw-r--r-- | sam.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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) { |
