diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-04 15:44:27 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-04 15:44:27 +0300 |
| commit | 66ffa8e6ea83f94d080171589675279671b5f175 (patch) | |
| tree | e851cf94e960570c92f6b59b0265ac98873adb8e | |
| parent | 04d6b474f928775ea0019928fdfbf08ecaae0997 (diff) | |
| download | astar-66ffa8e6ea83f94d080171589675279671b5f175.tar.xz | |
Error out on failure to realloc the stack
| -rw-r--r-- | map.c | 4 | ||||
| -rw-r--r-- | stack.c | 2 |
2 files changed, 3 insertions, 3 deletions
@@ -142,7 +142,7 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) { visited_clear(visited, width, height); PositionStack ps = ps_new(); - if (ps_push(&ps, beginning_cell) == -1) error("Is the STACK_SIZE zero?"); + ps_push(&ps, beginning_cell); visited[beginning_cell.y][beginning_cell.x] = 1; Position na[4]; @@ -154,7 +154,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); - if (ps_push(&ps, next) == -1) error("Stack overflow in rbt_maze_map(). Recompile with bigger STACK_SIZE or decrease the map size\n"); + ps_push(&ps, next); visited[next.y][next.x] = 1; map[(next.y * 2 + prev.y * 2) / 2][(next.x * 2 + prev.x * 2) / 2] = EMPTY; } else { @@ -15,7 +15,7 @@ PositionStack ps_new(void) { int ps_push(PositionStack *ps, Position pos) { if (ps->top >= ps->capacity) { ps->capacity *= STACK_SIZE_COEFFICIENT; - if ((ps->arr = realloc(ps->arr, sizeof(Position) * ps->capacity)) == NULL) return -1; + if ((ps->arr = realloc(ps->arr, sizeof(Position) * ps->capacity)) == NULL) error("Failed to realloc ps->arr\n"); } ps->arr[ps->top] = pos; ps->top += 1; |
