chiark / gitweb /
Correct a logic error in Unequal game desc validation.
authorSimon Tatham <anakin@pobox.com>
Sun, 11 Dec 2016 09:19:30 +0000 (09:19 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 11 Dec 2016 09:19:30 +0000 (09:19 +0000)
A user points out that the error check that should have detected a
non-digit where a digit should have been was never firing, due to an
&& that should have been ||.

I don't think it was a harmful error - the subsequent check that the
number was in range, plus the skipping past only digits to find the
next part of the string, combine to arrange that not many kinds of
invalid game id could actually get through.

But it did have the small effect that a 0 could be elided without
triggering an error, e.g. the game ids

  4:0,0,0,0,0,0L,0,0,0R,0U,0,0L,0,0,,3,
  4:0,0,0,0,0,0L,0,0,0R,0U,0,0L,0,0,0,3,

would both be accepted, and would be decoded into the same game, even
though the former should have failed syntax validation. Now it does.

unequal.c

index 1c8984a14eceb790543fc8484e42c8b9ce79b0b7..3664788154e4f2a715cafde334fd2391eb4b76b5 100644 (file)
--- a/unequal.c
+++ b/unequal.c
@@ -1214,7 +1214,7 @@ static game_state *load_game(const game_params *params, const char *desc,
             why = "Too much data to fill grid"; goto fail;
         }
 
-        if (*p < '0' && *p > '9') {
+        if (*p < '0' || *p > '9') {
             why = "Expecting number in game description"; goto fail;
         }
         n = atoi(p);