shithub: puzzles

Download patch

ref: 91d96fa0bc133c8d967f3c4b01804e7773de8504
parent: 5c36e1536a05abf514b09476813cf71bc9dc1e31
author: Ben Harris <bjh21@bjh21.me.uk>
date: Tue Jan 10 15:24:59 EST 2023

Last-ditch maximum size limit for Sixteen

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

--- a/sixteen.c
+++ b/sixteen.c
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -173,6 +174,8 @@
 {
     if (params->w < 2 || params->h < 2)
 	return "Width and height must both be at least two";
+    if (params->w > INT_MAX / params->h)
+        return "Width times height must not be unreasonably large";
 
     return NULL;
 }