shithub: puzzles

Download patch

ref: 261a9568faeeb7acc6e56bd67147917c5109ac8a
parent: d71bba1a17d6b228e7dd8b437dccbd3f6bc4698c
author: Ben Harris <[email protected]>
date: Wed Jan 11 04:43:01 EST 2023

Last-ditch maximum size limit for Magnets

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

--- a/magnets.c
+++ b/magnets.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -232,6 +233,8 @@
 {
     if (params->w < 2) return "Width must be at least two";
     if (params->h < 2) return "Height must be at least two";
+    if (params->w > INT_MAX / params->h)
+        return "Width times height must not be unreasonably large";
     if (params->diff >= DIFF_TRICKY) {
         if (params->w < 5 && params->h < 5)
             return "Either width or height must be at least five for Tricky";