shithub: puzzles

Download patch

ref: fcda12f4b73e69841fd8957b8e33930c584093e5
parent: 98724b90936c46e457234a0189bb09242fc727d1
author: Ben Harris <bjh21@bjh21.me.uk>
date: Tue Jan 10 15:31:10 EST 2023

Last-ditch maximum size limit for Light Up

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

--- a/lightup.c
+++ b/lightup.c
@@ -47,6 +47,7 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -346,6 +347,8 @@
 {
     if (params->w < 2 || params->h < 2)
         return "Width and height must be at least 2";
+    if (params->w > INT_MAX / params->h)
+        return "Width times height must not be unreasonably large";
     if (full) {
         if (params->blackpc < 5 || params->blackpc > 100)
             return "Percentage of black squares must be between 5% and 100%";