From 9339cff533fcbf441feef1a5f19163619f8ec1c9 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 11 Dec 2021 11:09:29 +0000 Subject: [PATCH] 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. --- palisade.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/palisade.c b/palisade.c index a82a8c1..58619bf 100644 --- a/palisade.c +++ b/palisade.c @@ -46,7 +46,7 @@ struct game_params { int w, h, k; }; -typedef char clue; +typedef signed char clue; typedef unsigned char borderflag; typedef struct shared_state { @@ -622,7 +622,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, { 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 @@ static char *new_game_desc(const game_params *params, random_state *rs, 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 @@ static char *new_game_desc(const game_params *params, random_state *rs, } *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)