Don't allow Bridges games with < 2 islands

Technically, a game with no islands is always solved, but it causes a
null-pointer dereference at startup because there's nowhere to put the
cursor.  Games with one island are always insoluble because the island
must have at least one bridge and there's nowhere for it to go.  So
the minimum playable game has two islands.

To demonstrate the segfault, try loading this save file:

SAVEFILE:41:Simon Tatham's Portable Puzzle Collection
VERSION :1:1
GAME    :7:Bridges
PARAMS  :1:3
CPARAMS :1:3
DESC    :1:i
NSTATES :1:1
STATEPOS:1:1
This commit is contained in:
Ben Harris
2023-01-28 00:45:38 +00:00
parent 1f72a1a2ec
commit a98ac4bb42

View File

@ -2007,15 +2007,15 @@ generated:
static const char *validate_desc(const game_params *params, const char *desc)
{
int i, wh = params->w * params->h;
int i, wh = params->w * params->h, nislands = 0;
for (i = 0; i < wh; i++) {
if (*desc >= '1' && *desc <= '9')
/* OK */;
nislands++;
else if (*desc >= 'a' && *desc <= 'z')
i += *desc - 'a'; /* plus the i++ */
else if (*desc >= 'A' && *desc <= 'G')
/* OK */;
nislands++;
else if (!*desc)
return "Game description shorter than expected";
else
@ -2024,6 +2024,8 @@ static const char *validate_desc(const game_params *params, const char *desc)
}
if (*desc || i > wh)
return "Game description longer than expected";
if (nislands < 2)
return "Game description has too few islands";
return NULL;
}