From 7719755a52a56126a88c3d6898d27779865e8f09 Mon Sep 17 00:00:00 2001 From: Ry Date: Mon, 30 Jan 2023 14:07:43 -0800 Subject: [PATCH] Cleanly exit if attempting to open non-existent disk Fixes issue #7. --- src/disk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/disk.c b/src/disk.c index bac0503..27ea0f7 100644 --- a/src/disk.c +++ b/src/disk.c @@ -19,6 +19,10 @@ void new_disk(const char *filename, size_t id) { if (id > 3) { puts("attempting to access disk with ID > 3\n"); return; } printf("mounting %s as disk ID %d\n", filename, (int) id); disk_controller.disks[id].file = fopen(filename, "r+b"); + if (!disk_controller.disks[id].file) { + fprintf(stderr, "couldn't open disk file\n"); + exit(1); + } fseek(disk_controller.disks[id].file, 0, SEEK_END); disk_controller.disks[id].size = ftell(disk_controller.disks[id].file); rewind(disk_controller.disks[id].file);