diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2023-01-10 00:28:09 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-01-15 16:24:27 +0000 |
| commit | 91c0fac1dc98be2ecc074d83368df74f9f755641 (patch) | |
| tree | 45e0a510fb84f57799869840b6a321768793d15d /palisade.c | |
| parent | dd00e9c532abc7517bd7ca72c8e4db91bb2da821 (diff) | |
| download | puzzles-91c0fac1dc98be2ecc074d83368df74f9f755641.zip puzzles-91c0fac1dc98be2ecc074d83368df74f9f755641.tar.gz puzzles-91c0fac1dc98be2ecc074d83368df74f9f755641.tar.bz2 puzzles-91c0fac1dc98be2ecc074d83368df74f9f755641.tar.xz | |
Last-ditch maximum size limit for Palisade
This makes sure that width * height <= INT_MAX, which it rather needs
to be.
Diffstat (limited to 'palisade.c')
| -rw-r--r-- | palisade.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -17,6 +17,7 @@ #include <assert.h> #include <ctype.h> +#include <limits.h> #include <stdarg.h> #include <stdio.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) { - 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 (w < 1) return "Width 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 (!full) return NULL; /* succeed partial validation */ /* MAYBE FIXME: we (just?) don't have the UI for winning these. */ |