aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2017-08-14 17:22:59 -0400
committerFranklin Wei <me@fwei.tk>2018-12-21 21:39:34 -0500
commita1207f15534f11c671d278999285848d42eb2d09 (patch)
treea613181022fadd2e7ece564592302439cc5a131c
parent700da0350d9e4846bab7f179406d78c5a2a50690 (diff)
downloadpuzzles-a1207f15534f11c671d278999285848d42eb2d09.zip
puzzles-a1207f15534f11c671d278999285848d42eb2d09.tar.gz
puzzles-a1207f15534f11c671d278999285848d42eb2d09.tar.bz2
puzzles-a1207f15534f11c671d278999285848d42eb2d09.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 3067fbf..c52c508 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 cb1ef28..67c3225 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 00d306c..41d0584 100644
--- a/mines.c
+++ b/mines.c
@@ -260,6 +260,8 @@ static const char *validate_params(const game_params *params, bool full)
return "Width and height must both be greater than two";
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 bb658fc..ec8ff4f 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 ffadd3f..42f3fc5 100644
--- a/pattern.c
+++ b/pattern.c
@@ -175,6 +175,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 ba60a86..e47147a 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 06f6ff1..1d91559 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;
}