aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-12-11 11:09:29 +0000
committerSimon Tatham <anakin@pobox.com>2021-12-11 11:09:29 +0000
commit9339cff533fcbf441feef1a5f19163619f8ec1c9 (patch)
treebb0af23b83bba59263b9e6b4082cd5b978ce5cde
parent3e006158451a7ff8f130cbcb7dd80f165a58396e (diff)
downloadpuzzles-9339cff533fcbf441feef1a5f19163619f8ec1c9.zip
puzzles-9339cff533fcbf441feef1a5f19163619f8ec1c9.tar.gz
puzzles-9339cff533fcbf441feef1a5f19163619f8ec1c9.tar.bz2
puzzles-9339cff533fcbf441feef1a5f19163619f8ec1c9.tar.xz
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.
-rw-r--r--palisade.c10
1 files 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)