shithub: puzzles

Download patch

ref: 91c0fac1dc98be2ecc074d83368df74f9f755641
parent: dd00e9c532abc7517bd7ca72c8e4db91bb2da821
author: Ben Harris <bjh21@bjh21.me.uk>
date: Mon Jan 9 19:28:09 EST 2023

Last-ditch maximum size limit for Palisade

This makes sure that width * height <= INT_MAX, which it rather needs
to be.

--- a/palisade.c
+++ b/palisade.c
@@ -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 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. */