diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-12 10:29:51 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-12 10:29:51 +0000 |
commit | cac30055faf199136f9fa14b3ed866c9b78ed022 (patch) | |
tree | ded6b45ee989fc4f4ade5b1f2a519114c9f4ac46 | |
parent | 4f257b7952bcfa0af57882bf8558ad41e9fc32a9 (diff) |
Don't infinite loop if we never reach the end point
-rw-r--r-- | 12.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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); |