chiark / gitweb /
deserialise: use the right one of {,c}params.
authorSimon Tatham <anakin@pobox.com>
Sun, 1 Oct 2017 08:15:49 +0000 (09:15 +0100)
committerSimon Tatham <anakin@pobox.com>
Sun, 1 Oct 2017 08:51:01 +0000 (09:51 +0100)
The serialised game stores a long-term and a short-term parameter
structure, which correspond to me->params (the thing that gets used by
the next New Game command) and me->curparams (the thing that _was_
used to generate _this_ game). So data relevant to the current game
ought to be validated against the latter, but in fact I was
accidentally passing the former to several validation calls.

I think this probably avoided causing a problem because typically
params and cparams don't differ very much: the usual reason why
they're not the same is that somebody has manually entered a game
description involving an incomplete description of the parameters
(lacking generation-specific details like difficulty level), but by
the very fact that those incomplete descriptions have to contain
_enough_ information to understand a specific game description,
copying just those parts of the description into the long-term params
structure makes the two similar enough that validation won't fail.

However, testing an upcoming patch which calls midend_deserialise at a
more difficult moment (specifically, just after midend_set_params,
meaning that the two params structures can now differ _arbitrarily_)
reveals my error. Fixed to use cparams where that's the right thing.

midend.c

index 2edc1ec6ef4286a4124f7d2f440a0b2ed472dee2..536c3e8c420cceb6e284c0183db3bc2a2a869566 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -1951,11 +1951,11 @@ char *midend_deserialise(midend *me,
     if (!desc) {
         ret = "Game description in save file is missing";
         goto cleanup;
-    } else if (me->ourgame->validate_desc(params, desc)) {
+    } else if (me->ourgame->validate_desc(cparams, desc)) {
         ret = "Game description in save file is invalid";
         goto cleanup;
     }
-    if (privdesc && me->ourgame->validate_desc(params, privdesc)) {
+    if (privdesc && me->ourgame->validate_desc(cparams, privdesc)) {
         ret = "Game private description in save file is invalid";
         goto cleanup;
     }
@@ -1963,7 +1963,7 @@ char *midend_deserialise(midend *me,
         ret = "Game position in save file is out of range";
     }
 
-    states[0].state = me->ourgame->new_game(me, params,
+    states[0].state = me->ourgame->new_game(me, cparams,
                                             privdesc ? privdesc : desc);
     for (i = 1; i < nstates; i++) {
         assert(states[i].movetype != NEWGAME);
@@ -1978,11 +1978,11 @@ char *midend_deserialise(midend *me,
             }
             break;
           case RESTART:
-            if (me->ourgame->validate_desc(params, states[i].movestr)) {
+            if (me->ourgame->validate_desc(cparams, states[i].movestr)) {
                 ret = "Save file contained an invalid restart move";
                 goto cleanup;
             }
-            states[i].state = me->ourgame->new_game(me, params,
+            states[i].state = me->ourgame->new_game(me, cparams,
                                                     states[i].movestr);
             break;
         }