diff options
| -rw-r--r-- | map.c | 4 | ||||
| -rw-r--r-- | stack.c | 5 |
2 files changed, 6 insertions, 3 deletions
@@ -123,7 +123,7 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) { memset(visited, 0, sizeof(char) * width * height); PositionStack ps = ps_new(); - ps_push(&ps, beginning_cell); + if (ps_push(&ps, beginning_cell) == -1) error("Is the STACK_SIZE zero?"); visited[beginning_cell.y][beginning_cell.x] = 1; Position na[4]; @@ -135,7 +135,7 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) { if (nc > 0) { Position next = na[rand() % nc]; Position prev = ps_peek(ps); - ps_push(&ps, next); + if (ps_push(&ps, next) == -1) error("Stack overflow in rbt_maze_map(). Recompile with bigger STACK_SIZE or decrease the map size\n"); visited[next.y][next.x] = 1; map[(next.y * 2 + prev.y * 2) / 2][(next.x * 2 + prev.x * 2) / 2] = EMPTY; } else { @@ -1,5 +1,8 @@ #include "stack.h" #include "structs.h" +#include "error.h" +#include "curses.h" /* Required by error.h */ +#include "stdio.h" /* Required by error.h */ PositionStack ps_new(void) { PositionStack ps; @@ -8,7 +11,7 @@ PositionStack ps_new(void) { } int ps_push(PositionStack *ps, Position pos) { - /*TODO: check for stack overflow */ + if (ps->top >= STACK_SIZE) return -1; ps->arr[ps->top] = pos; ps->top += 1; return 0; |
