From 4ffcd5dc8b0adf017148c5a88193a8562616303d Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 14 Aug 2017 17:22:59 -0400 Subject: Add more config validity checks --- blackbox.c | 2 ++ flood.c | 4 +++- mines.c | 2 ++ netslide.c | 2 ++ pattern.c | 2 ++ sixteen.c | 3 ++- twiddle.c | 2 ++ 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/blackbox.c b/blackbox.c index 5a6be4e..a9c1f88 100644 --- a/blackbox.c +++ b/blackbox.c @@ -196,6 +196,8 @@ static const char *validate_params(const game_params *params, bool full) return "Minimum number of balls may not be greater than maximum"; if (params->minballs >= params->w * params->h) return "Too many balls to fit in grid"; + if (params->minballs < 1) + return "Number of balls must be at least one"; return NULL; } diff --git a/flood.c b/flood.c index ea43302..74214a5 100644 --- a/flood.c +++ b/flood.c @@ -207,8 +207,10 @@ 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 both be at least one"; if (params->colours < 3 || params->colours > 10) return "Must have between 3 and 10 colours"; if (params->leniency < 0) diff --git a/mines.c b/mines.c index b48dc30..0a2407e 100644 --- a/mines.c +++ b/mines.c @@ -262,6 +262,8 @@ static const char *validate_params(const game_params *params, bool full) return "Mine count may not be negative"; if (params->n > params->w * params->h - 9) 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 diff --git a/netslide.c b/netslide.c index 7465d70..a2e3281 100644 --- a/netslide.c +++ b/netslide.c @@ -311,6 +311,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; } diff --git a/pattern.c b/pattern.c index b9a3d6e..df720b7 100644 --- a/pattern.c +++ b/pattern.c @@ -176,6 +176,8 @@ static const char *validate_params(const game_params *params, bool full) { if (params->w <= 0 || params->h <= 0) 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; } diff --git a/sixteen.c b/sixteen.c index d153e50..0b02038 100644 --- a/sixteen.c +++ b/sixteen.c @@ -173,7 +173,8 @@ static const char *validate_params(const game_params *params, bool full) { if (params->w < 2 || params->h < 2) 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; } diff --git a/twiddle.c b/twiddle.c index 32716e5..a107925 100644 --- a/twiddle.c +++ b/twiddle.c @@ -210,6 +210,8 @@ static const char *validate_params(const game_params *params, bool full) return "Width must be at least the rotating block size"; if (params->h < params->n) 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; } -- cgit v1.1