mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Last-ditch maximum size limit for Palisade
This makes sure that width * height <= INT_MAX, which it rather needs to be.
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -156,13 +157,15 @@ 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)
|
||||||
{
|
{
|
||||||
int w = params->w, h = params->h, k = params->k, wh = w * h;
|
int w = params->w, h = params->h, k = params->k, wh;
|
||||||
|
|
||||||
if (k < 1) return "Region size must be at least one";
|
if (k < 1) return "Region size must be at least one";
|
||||||
if (w < 1) return "Width must be at least one";
|
if (w < 1) return "Width must be at least one";
|
||||||
if (h < 1) return "Height must be at least one";
|
if (h < 1) return "Height must be at least one";
|
||||||
|
if (w > INT_MAX / h)
|
||||||
|
return "Width times height must not be unreasonably large";
|
||||||
|
wh = w * h;
|
||||||
if (wh % k) return "Region size must divide grid area";
|
if (wh % k) return "Region size must divide grid area";
|
||||||
|
|
||||||
if (!full) return NULL; /* succeed partial validation */
|
if (!full) return NULL; /* succeed partial validation */
|
||||||
|
|
||||||
/* MAYBE FIXME: we (just?) don't have the UI for winning these. */
|
/* MAYBE FIXME: we (just?) don't have the UI for winning these. */
|
||||||
|
Reference in New Issue
Block a user