1
0
Fork 0
forked from len0rd/rockbox

puzzles: add more parameter validation checks

Fixes some annoying crashes.

Change-Id: If3c293bd90e301c3e697d1e5fcb1b0aa2ea320fb
This commit is contained in:
Franklin Wei 2017-08-16 11:37:10 -04:00
parent c78ff7f615
commit f31a400bac
7 changed files with 15 additions and 2 deletions

View file

@ -200,6 +200,8 @@ static char *validate_params(const game_params *params, int full)
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)
return "Too many balls to fit in grid"; return "Too many balls to fit in grid";
if (params->minballs < 1)
return "Number of balls must be at least one";
return NULL; return NULL;
} }

View file

@ -213,8 +213,10 @@ static game_params *custom_params(const config_item *cfg)
static char *validate_params(const game_params *params, int full) static char *validate_params(const game_params *params, int 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)
return "Width and height must both be at least one";
if (params->colours < 3 || params->colours > 10) if (params->colours < 3 || params->colours > 10)
return "Must have between 3 and 10 colours"; return "Must have between 3 and 10 colours";
if (params->leniency < 0) if (params->leniency < 0)

View file

@ -265,6 +265,8 @@ static char *validate_params(const game_params *params, int full)
return "Width and height must both be greater than two"; return "Width and height must both be greater than two";
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";
if (params->n < 1)
return "Number of mines must be greater than zero";
/* /*
* FIXME: Need more constraints here. Not sure what the * FIXME: Need more constraints here. Not sure what the

View file

@ -320,6 +320,8 @@ static char *validate_params(const game_params *params, int 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;
} }

View file

@ -179,6 +179,8 @@ static char *validate_params(const game_params *params, int full)
{ {
if (params->w <= 0 || params->h <= 0) if (params->w <= 0 || params->h <= 0)
return "Width and height must both be greater than zero"; return "Width and height must both be greater than zero";
if (params->w * params->w < 2)
return "Grid must contain at least two squares";
return NULL; return NULL;
} }

View file

@ -178,7 +178,8 @@ static char *validate_params(const game_params *params, int full)
{ {
if (params->w < 2 || params->h < 2) if (params->w < 2 || params->h < 2)
return "Width and height must both be at least two"; return "Width and height must both be at least two";
if (params->movetarget < 0)
return "Number of shuffling moves may not be negative";
return NULL; return NULL;
} }

View file

@ -217,6 +217,8 @@ static char *validate_params(const game_params *params, int full)
return "Width must be at least the rotating block size"; return "Width must be at least the rotating block size";
if (params->h < params->n) if (params->h < params->n)
return "Height must be at least the rotating block size"; return "Height must be at least the rotating block size";
if (params->movetarget < 0)
return "Number of shuffling moves may not be negative";
return NULL; return NULL;
} }