From f5c8ef8789c3f5554a48861c990ab1e327964273 Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Tue, 5 Sep 2023 14:17:34 +0200 Subject: [PATCH] Path check, when creating stack --- src/turtle/stack.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/turtle/stack.c b/src/turtle/stack.c index a351a4d..3f74974 100644 --- a/src/turtle/stack.c +++ b/src/turtle/stack.c @@ -62,10 +62,13 @@ enum turtle_return turtle_stack_create(struct turtle_stack ** stack, double lat_delta = 0., long_delta = 0.; int data_size = strlen(path) + 1; - int rc; tinydir_dir dir; - for (rc = tinydir_open(&dir, path); (rc == 0) && dir.has_next; - tinydir_next(&dir)) { + int rc = tinydir_open(&dir, path); + if (rc != 0) { + return TURTLE_ERROR_FORMAT( + TURTLE_RETURN_PATH_ERROR, "could not access %s", path); + } + for (; dir.has_next; tinydir_next(&dir)) { tinydir_file file; tinydir_readfile(&dir, &file); if (file.is_dir) continue; @@ -119,7 +122,7 @@ enum turtle_return turtle_stack_create(struct turtle_stack ** stack, tinydir_close(&dir); return TURTLE_ERROR_RAISE(); } - if (rc == 0) tinydir_close(&dir); + tinydir_close(&dir); /* Check the grid size */ int lat_n = 0, long_n = 0;