Skip to content

Commit

Permalink
Do a size_t size sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
TurkeyMcMac committed Apr 9, 2021
1 parent ca3e9f4 commit 55a71e9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/maze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* The version of the program: */
#define VERSION "0.5.12"
#define VERSION "0.5.13"

0 comments on commit 55a71e9

Please sign in to comment.