chiark / gitweb /
Fix a compile warning on ARM.
authorSimon Tatham <anakin@pobox.com>
Tue, 24 Mar 2015 19:20:03 +0000 (19:20 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 24 Mar 2015 19:20:03 +0000 (19:20 +0000)
Aapo Rantalainen points out that comparing 'char c' against zero gives
rise to gcc's "comparison is always false" warning, which escalates to
an error under -Werror.

This is one of those situations where the warning is doing more harm
than good, but here's a rephrasing which casts to unsigned so that
both negative numbers and positive out-of-range ones can be caught by
the same comparison.

flood.c

diff --git a/flood.c b/flood.c
index 557da953b4a275455f7e0e66358fae010aad8ebb..bbba91528bdee8f82e9993f122fa80deb7a72bf7 100644 (file)
--- a/flood.c
+++ b/flood.c
@@ -609,7 +609,7 @@ static char *validate_desc(const game_params *params, const char *desc)
             c = 10 + (c - 'A');
         else
             return "Bad character in grid description";
-        if (c < 0 || c >= params->colours)
+        if ((unsigned)c >= params->colours)
             return "Colour out of range in grid description";
     }
     if (*desc != ',')