From 55a71e9e585d66e5af170081d8229bdfa8ad8a01 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Fri, 9 Apr 2021 15:30:40 -0400 Subject: [PATCH] Do a size_t size sanity check --- src/maze.c | 2 ++ src/version.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/maze.c b/src/maze.c index c901c21..04e852d 100644 --- a/src/maze.c +++ b/src/maze.c @@ -146,6 +146,8 @@ int maze_generate(struct maze *maze, int width_nodes, int height_nodes, /* Convert the dimensions in nodes to dimensions in tiles. */ maze->width = width_nodes * 2 - 1; maze->height = height_nodes * 2 - 1; + /* Check that size_t can fit the number of tiles then try allocating. */ + if ((size_t)-1 < 32767U) goto error_maze_alloc; maze->tiles = calloc((size_t)(maze->width * maze->height), sizeof(*maze->tiles)); if (!maze->tiles) goto error_maze_alloc; diff --git a/src/version.h b/src/version.h index 02ec632..5e41ad9 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ /* The version of the program: */ -#define VERSION "0.5.12" +#define VERSION "0.5.13"