aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-22 20:58:28 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-22 20:58:28 +0300
commit092fbe195d22dfecb768c98f91b6ab733f1bb72f (patch)
tree067b3d2f4b332a9b9b0456777cf9b9f3dccc8eb8 /path.c
parent55b10d144a6855791f3918f37ccdf36fd8109e58 (diff)
downloadastar-092fbe195d22dfecb768c98f91b6ab733f1bb72f.tar.xz
Clean up path_reverse()
Diffstat (limited to 'path.c')
-rw-r--r--path.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/path.c b/path.c
index 19a9aaa..15c7e31 100644
--- a/path.c
+++ b/path.c
@@ -332,6 +332,7 @@ void path_free(Path path, size_t height) {
void path_reverse(Path *path, size_t width, size_t height, Position *start, Position *end) {
Path new_path = path_new(width, height);
+ if (new_path == NULL) error("Failed to allocate path\n");
Position cur = *end;
while (cur.x != start->x || cur.y != start->y) {
@@ -341,16 +342,18 @@ void path_reverse(Path *path, size_t width, size_t height, Position *start, Posi
}
/* Switch start and end around */
- start->x = start->x ^ end->x;
- end->x = start->x ^ end->x;
- start->x = start->x ^ end->x;
+ start->x ^= end->x;
+ end->x ^= start->x;
+ start->x ^= end->x;
- start->y = start->y ^ end->y;
- end->y = start->y ^ end->y;
- start->y = start->y ^ end->y;
+ start->y ^= end->y;
+ end->y ^= start->y;
+ start->y ^= end->y;
path_free(*path, height);
*path = new_path;
+
+ return;
}
char **visited_new(size_t width, size_t height) {