aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2017-08-14 17:22:59 -0400
committerFranklin Wei <franklin@rockbox.org>2020-12-07 19:27:19 -0500
commit4ffcd5dc8b0adf017148c5a88193a8562616303d (patch)
treee1f784e07f9e191d640437fa484d9e0fedac3ae4
parent6752afa4968826f10b2755d318fd873228ec670d (diff)
downloadpuzzles-4ffcd5dc8b0adf017148c5a88193a8562616303d.zip
puzzles-4ffcd5dc8b0adf017148c5a88193a8562616303d.tar.gz
puzzles-4ffcd5dc8b0adf017148c5a88193a8562616303d.tar.bz2
puzzles-4ffcd5dc8b0adf017148c5a88193a8562616303d.tar.xz
Add more config validity checks
-rw-r--r--blackbox.c2
-rw-r--r--flood.c4
-rw-r--r--mines.c2
-rw-r--r--netslide.c2
-rw-r--r--pattern.c2
-rw-r--r--sixteen.c3
-rw-r--r--twiddle.c2
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;
}