vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit ad77f9b53bf11d16c142f24932e36bb744340f01
parent ff96ac485fc2e9f53794028d745b6938ccb757ad
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu,  9 Feb 2017 11:24:51 +0100

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:
Msam.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 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) {