summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-12 10:29:51 +0000
committerAdam Spragg <adam@spra.gg>2022-12-12 10:29:51 +0000
commitcac30055faf199136f9fa14b3ed866c9b78ed022 (patch)
treeded6b45ee989fc4f4ade5b1f2a519114c9f4ac46
parent4f257b7952bcfa0af57882bf8558ad41e9fc32a9 (diff)
Don't infinite loop if we never reach the end point
-rw-r--r--12.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/12.c b/12.c
index c647410..42d63d4 100644
--- a/12.c
+++ b/12.c
@@ -136,7 +136,7 @@ main()
range[front->x + front->y * cols] |= 0x80;
// Take steps, widening the search front each iteration.
- for (steps = 0; 1; ++steps) {
+ for (steps = 0; front != NULL; ++steps) {
struct pos * nextfront = NULL;
struct pos * loc;
@@ -166,7 +166,10 @@ main()
front = nextfront;
}
- printf("Found end at %d,%d in %d steps\n", front->x, front->y, steps);
+ if (front)
+ printf("Found end at %d,%d in %d steps\n", front->x, front->y, steps);
+ else
+ printf("No end found after %d steps\n", steps);
pos_free(front);
free(range);