Add more configuration parameter lower-bound checks.

This commit is contained in:
Franklin Wei
2024-07-21 18:54:43 -04:00
committed by Simon Tatham
parent a2f7f962ce
commit af3ab1cc5d
7 changed files with 13 additions and 2 deletions

View File

@ -198,6 +198,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Widths and heights greater than 255 are not supported";
if (params->minballs < 0)
return "Negative number of balls";
if (params->minballs < 1)
return "Number of balls must be at least one";
if (params->minballs > params->maxballs)
return "Minimum number of balls may not be greater than maximum";
if (params->minballs >= params->w * params->h)

View File

@ -212,7 +212,7 @@ static game_params *custom_params(const config_item *cfg)
static const char *validate_params(const game_params *params, bool full)
{
if (params->w < 2 && params->h < 2)
if (params->w * params->h < 2)
return "Grid must contain at least two squares";
if (params->w < 1 || params->h < 1)
return "Width and height must be at least one";

View File

@ -279,6 +279,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Width times height must not be unreasonably large";
if (params->n < 0)
return "Mine count may not be negative";
if (params->n < 1)
return "Number of mines must be greater than zero";
if (params->n > params->w * params->h - 9)
return "Too many mines for grid size";

View File

@ -318,6 +318,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Barrier probability may not be negative";
if (params->barrier_probability > 1)
return "Barrier probability may not be greater than 1";
if (params->movetarget < 0)
return "Number of shuffling moves may not be negative";
return NULL;
}

View File

@ -185,6 +185,8 @@ static const char *validate_params(const game_params *params, bool full)
if (params->w > INT_MAX - 1 || params->h > INT_MAX - 1 ||
params->w > INT_MAX / params->h)
return "Puzzle must not be unreasonably large";
if (params->w * params->h < 2)
return "Grid must contain at least two squares";
return NULL;
}

View File

@ -180,7 +180,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Width and height must both be at least two";
if (params->w > INT_MAX / params->h)
return "Width times height must not be unreasonably large";
if (params->movetarget < 0)
return "Number of shuffling moves may not be negative";
return NULL;
}

View File

@ -219,6 +219,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Height must be at least the rotating block size";
if (params->w > INT_MAX / params->h)
return "Width times height must not be unreasonably large";
if (params->movetarget < 0)
return "Number of shuffling moves may not be negative";
return NULL;
}