From 71a446f7df79863738eb0bc5eb4e54551905deec Mon Sep 17 00:00:00 2001 From: Christian C Date: Thu, 6 Mar 2025 15:52:00 -0800 Subject: Convert file loop For loop rather than while --- src/main.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 156a873..fdabaf5 100644 --- a/src/main.c +++ b/src/main.c @@ -91,16 +91,11 @@ int main(int argc, char** argv) if (is_directory(directory)) { // List files in the ddirectory file_list = list_directory(directory); - if (file_list) { - size_t index = 0; - // For each file - while (1) { + if (file_list != NULL) { + for (size_t index = 0; file_list[index] != NULL; index++) { char* fname = file_list[index]; - if (fname == NULL) { - break; - } if (is_tif_ext(fname) == FALSE) { - free(file_list[index++]); + free(file_list[index]); continue; } // If we have a tiff file @@ -110,7 +105,7 @@ int main(int argc, char** argv) // 4. Free up allocations made in this process char* fpath = full_path(directory, fname); if (fpath == NULL) { - free(file_list[index++]); + free(file_list[index]); continue; } if (!silent) { @@ -119,13 +114,13 @@ int main(int argc, char** argv) uint16_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label); if (file_labels == NULL) { free(fpath); - free(file_list[index++]); + free(file_list[index]); continue; } masks = combine_masks(masks, file_labels, width, height); free(file_labels); free(fpath); - free(file_list[index++]); + free(file_list[index]); } free(file_list); } -- cgit v1.2.1