shithub: puzzles

Download patch

ref: 9339cff533fcbf441feef1a5f19163619f8ec1c9
parent: 3e006158451a7ff8f130cbcb7dd80f165a58396e
author: Simon Tatham <anakin@pobox.com>
date: Sat Dec 11 06:09:29 EST 2021

Palisade: explicitly use 'signed char' for clues.

Previously, the typedef 'clue' was just 'char', but it was used in the
expectation that it would be signed. So on platforms that default to
unsigned char, such as 32-bit Arm, Palisade would completely fail to
function correctly.

--- a/palisade.c
+++ b/palisade.c
@@ -46,7 +46,7 @@
     int w, h, k;
 };
 
-typedef char clue;
+typedef signed char clue;
 typedef unsigned char borderflag;
 
 typedef struct shared_state {
@@ -622,7 +622,7 @@
 {
     int w = params->w, h = params->h, wh = w*h, k = params->k;
 
-    clue *numbers = snewn(wh + 1, clue), *p;
+    clue *numbers = snewn(wh + 1, clue);
     borderflag *rim = snewn(wh, borderflag);
     borderflag *scratch_borders = snewn(wh, borderflag);
 
@@ -682,7 +682,8 @@
     sfree(shuf);
     sfree(dsf);
 
-    p = numbers;
+    char *output = snewn(wh + 1, char), *p = output;
+
     r = 0;
     for (i = 0; i < wh; ++i) {
         if (numbers[i] != EMPTY) {
@@ -699,7 +700,8 @@
     }
     *p++ = '\0';
 
-    return sresize(numbers, p - numbers, clue);
+    sfree(numbers);
+    return sresize(output, p - output, char);
 }
 
 static const char *validate_desc(const game_params *params, const char *desc)