mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 15:41:30 -07:00
Add more configuration parameter lower-bound checks.
This commit is contained in:

committed by
Simon Tatham

parent
a2f7f962ce
commit
af3ab1cc5d
@ -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";
|
return "Widths and heights greater than 255 are not supported";
|
||||||
if (params->minballs < 0)
|
if (params->minballs < 0)
|
||||||
return "Negative number of balls";
|
return "Negative number of balls";
|
||||||
|
if (params->minballs < 1)
|
||||||
|
return "Number of balls must be at least one";
|
||||||
if (params->minballs > params->maxballs)
|
if (params->minballs > params->maxballs)
|
||||||
return "Minimum number of balls may not be greater than maximum";
|
return "Minimum number of balls may not be greater than maximum";
|
||||||
if (params->minballs >= params->w * params->h)
|
if (params->minballs >= params->w * params->h)
|
||||||
|
2
flood.c
2
flood.c
@ -212,7 +212,7 @@ static game_params *custom_params(const config_item *cfg)
|
|||||||
|
|
||||||
static const char *validate_params(const game_params *params, bool full)
|
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";
|
return "Grid must contain at least two squares";
|
||||||
if (params->w < 1 || params->h < 1)
|
if (params->w < 1 || params->h < 1)
|
||||||
return "Width and height must be at least one";
|
return "Width and height must be at least one";
|
||||||
|
2
mines.c
2
mines.c
@ -279,6 +279,8 @@ static const char *validate_params(const game_params *params, bool full)
|
|||||||
return "Width times height must not be unreasonably large";
|
return "Width times height must not be unreasonably large";
|
||||||
if (params->n < 0)
|
if (params->n < 0)
|
||||||
return "Mine count may not be negative";
|
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)
|
if (params->n > params->w * params->h - 9)
|
||||||
return "Too many mines for grid size";
|
return "Too many mines for grid size";
|
||||||
|
|
||||||
|
@ -318,6 +318,8 @@ static const char *validate_params(const game_params *params, bool full)
|
|||||||
return "Barrier probability may not be negative";
|
return "Barrier probability may not be negative";
|
||||||
if (params->barrier_probability > 1)
|
if (params->barrier_probability > 1)
|
||||||
return "Barrier probability may not be greater than 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 ||
|
if (params->w > INT_MAX - 1 || params->h > INT_MAX - 1 ||
|
||||||
params->w > INT_MAX / params->h)
|
params->w > INT_MAX / params->h)
|
||||||
return "Puzzle must not be unreasonably large";
|
return "Puzzle must not be unreasonably large";
|
||||||
|
if (params->w * params->h < 2)
|
||||||
|
return "Grid must contain at least two squares";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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";
|
return "Width and height must both be at least two";
|
||||||
if (params->w > INT_MAX / params->h)
|
if (params->w > INT_MAX / params->h)
|
||||||
return "Width times height must not be unreasonably large";
|
return "Width times height must not be unreasonably large";
|
||||||
|
if (params->movetarget < 0)
|
||||||
|
return "Number of shuffling moves may not be negative";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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";
|
return "Height must be at least the rotating block size";
|
||||||
if (params->w > INT_MAX / params->h)
|
if (params->w > INT_MAX / params->h)
|
||||||
return "Width times height must not be unreasonably large";
|
return "Width times height must not be unreasonably large";
|
||||||
|
if (params->movetarget < 0)
|
||||||
|
return "Number of shuffling moves may not be negative";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user