From 4e6af4dca5e2740671c2f87bffdd58c18a1b4608 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 1 Mar 2023 00:05:31 -0600 Subject: [PATCH] Bugfix: Miscellaneous problems in file functons and Featureless Make related code. Fix documentation inaccuracies such as "Set to 0 to not use." when 0 is not a "not use" value and is instead a valid value with discrete meaning. Remove documentation about non-existent parameter "file". Clarify the wording in some of the documentation. Add missing return on error check after several memory allocation function calls. Add missing range parameter checks. Error checking is being performed on wrong status variable and wrong status variable is being returned. Perform some general code clean up as encountered. --- level_0/f_directory/c/directory.c | 86 ++++++++----------------------- level_0/f_directory/c/private-directory.c | 4 +- level_0/f_file/c/file.h | 2 - level_0/f_file/c/private-file.h | 10 ---- level_0/f_fss/c/private-fss.c | 10 ++++ level_1/fl_directory/c/directory.h | 4 +- level_1/fl_directory/c/directory/common.h | 2 +- level_1/fl_fss/c/fss/basic_list.c | 1 + level_1/fl_fss/c/fss/embedded_list.c | 1 + level_1/fl_fss/c/fss/extended_list.c | 1 + level_2/fll_fss/c/fss/payload.c | 2 +- 11 files changed, 39 insertions(+), 84 deletions(-) diff --git a/level_0/f_directory/c/directory.c b/level_0/f_directory/c/directory.c index dea80e4..10d54da 100644 --- a/level_0/f_directory/c/directory.c +++ b/level_0/f_directory/c/directory.c @@ -8,9 +8,7 @@ extern "C" { #ifndef _di_f_directory_create_ f_status_t f_directory_create(const f_string_static_t path, const mode_t mode) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; return private_f_directory_create(path, mode); } @@ -19,9 +17,7 @@ extern "C" { #ifndef _di_f_directory_create_at_ f_status_t f_directory_create_at(const int at_id, const f_string_static_t path, const mode_t mode) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; return private_f_directory_create_at(at_id, path, mode); } @@ -30,9 +26,7 @@ extern "C" { #ifndef _di_f_directory_exists_ f_status_t f_directory_exists(const f_string_static_t path) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; @@ -51,9 +45,7 @@ extern "C" { return F_status_set_error(F_file_stat); } - if ((file_stat.st_mode & S_IFMT) == S_IFDIR) { - return F_true; - } + if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true; return F_false; } @@ -62,9 +54,7 @@ extern "C" { #ifndef _di_f_directory_exists_at_ f_status_t f_directory_exists_at(const int at_id, const f_string_static_t path, const int flag) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; @@ -84,9 +74,7 @@ extern "C" { return F_status_set_error(F_file_stat); } - if ((file_stat.st_mode & S_IFMT) == S_IFDIR) { - return F_true; - } + if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true; return F_false; } @@ -95,9 +83,7 @@ extern "C" { #ifndef _di_f_directory_is_ f_status_t f_directory_is(const f_string_static_t path) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; @@ -127,9 +113,7 @@ extern "C" { #ifndef _di_f_directory_is_at_ f_status_t f_directory_is_at(const int at_id, const f_string_static_t path, const int flag) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; @@ -149,9 +133,7 @@ extern "C" { return F_status_set_error(F_file_stat); } - if ((file_stat.st_mode & S_IFMT) == S_IFDIR) { - return F_true; - } + if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true; return F_false; } @@ -163,9 +145,7 @@ extern "C" { if (!names) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct dirent **listing = 0; f_status_t status = F_none; @@ -228,13 +208,8 @@ extern "C" { f_memory_delete(1, sizeof(struct dirent *), (void *) &listing); } - if (F_status_is_error(status)) { - return status; - } - - if (!length) { - return F_directory_empty; - } + if (F_status_is_error(status)) return status; + if (!length) return F_directory_empty; return F_none; } @@ -246,9 +221,7 @@ extern "C" { if (!id) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; int flag = F_directory_flag_directory_d | F_directory_flag_close_execute_d | F_directory_flag_path_d; @@ -287,9 +260,7 @@ extern "C" { if (!id) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; int flag = F_directory_flag_directory_d | F_directory_flag_close_execute_d | F_directory_flag_path_d; @@ -329,9 +300,7 @@ extern "C" { if (depth_max < 0) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; int result = 0; @@ -345,9 +314,7 @@ extern "C" { else { // Not recursively deleting and the path is requested to be preserved, so there is nothing to delete. - if (preserve) { - return F_none; - } + if (preserve) return F_none; result = remove(path.string); } @@ -383,9 +350,7 @@ extern "C" { if (depth_max < 0) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; int result = 0; @@ -399,9 +364,7 @@ extern "C" { else { // Not recursively deleting and the path is requested to be preserved, so there is nothing to delete. - if (preserve) { - return F_none; - } + if (preserve) return F_none; result = remove(path.string); } @@ -434,19 +397,14 @@ extern "C" { #ifndef _di_f_directory_touch_ f_status_t f_directory_touch(const f_string_static_t path, const mode_t mode) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; memset(&file_stat, 0, sizeof(struct stat)); if (stat(path.string, &file_stat) < 0) { - if (errno == ENOENT) { - return private_f_directory_create(path, mode); - } - + if (errno == ENOENT) return private_f_directory_create(path, mode); if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == ELOOP) return F_status_set_error(F_loop); @@ -481,9 +439,7 @@ extern "C" { #ifndef _di_f_directory_touch_at_ f_status_t f_directory_touch_at(const int at_id, const f_string_static_t path, const mode_t mode, const int flag) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; struct stat file_stat; diff --git a/level_0/f_directory/c/private-directory.c b/level_0/f_directory/c/private-directory.c index a007138..218650b 100644 --- a/level_0/f_directory/c/private-directory.c +++ b/level_0/f_directory/c/private-directory.c @@ -61,9 +61,7 @@ extern "C" { #if !defined(_di_f_directory_remove_) int private_f_directory_remove_recursively(const char * const path, const struct stat *file_stat, int type, struct FTW *entity) { - if (!entity->level) { - return 0; - } + if (!entity->level) return 0; return remove(path); } diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 0ae9c1f..f9c938d 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -1395,7 +1395,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. @@ -1441,7 +1440,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. diff --git a/level_0/f_file/c/private-file.h b/level_0/f_file/c/private-file.h index 4c6519e..0366945 100644 --- a/level_0/f_file/c/private-file.h +++ b/level_0/f_file/c/private-file.h @@ -113,10 +113,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * @param file - * The data related to the file being opened. - * This will be updated with the file descriptor. - * This will be updated with the create flag (ignoring and overriding existing file.flag). * @param exclusive * If TRUE, will fail when file already exists. * If FALSE, will not fail if file already exists. @@ -157,10 +153,6 @@ extern "C" { * * @param at_id * The parent directory, as an open directory file descriptor, in which path is relative to. - * @param file - * The data related to the file being opened. - * This will be updated with the file descriptor. - * This will be updated with the create flag (ignoring and overriding existing file.flag). * @param path * The path file name. * @param mode @@ -591,7 +583,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. @@ -624,7 +615,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. diff --git a/level_0/f_fss/c/private-fss.c b/level_0/f_fss/c/private-fss.c index 1605e88..89a96b2 100644 --- a/level_0/f_fss/c/private-fss.c +++ b/level_0/f_fss/c/private-fss.c @@ -11,7 +11,9 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < items->size; ++i) { + macro_f_fss_item_t_adjust(status, items->array[i], 0) + if (F_status_is_error(status)) return status; } // for status = f_memory_adjust(items->size, length, sizeof(f_fss_item_t), (void **) & items->array); @@ -36,7 +38,9 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < items->size; ++i) { + macro_f_fss_item_t_resize(status, items->array[i], 0) + if (F_status_is_error(status)) return status; } // for status = f_memory_resize(items->size, length, sizeof(f_fss_item_t), (void **) & items->array); @@ -94,6 +98,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nameds->size; ++i) { + status = private_f_fss_named_adjust(0, &nameds->array[i]); if (F_status_is_error(status)) return status; } // for @@ -120,6 +125,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nameds->size; ++i) { + status = private_f_fss_named_resize(0, &nameds->array[i]); if (F_status_is_error(status)) return status; } // for @@ -143,6 +149,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nest->size; ++i) { + status = private_f_fss_items_adjust(0, &nest->depth[i]); if (F_status_is_error(status)) return status; } // for @@ -169,6 +176,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nest->size; ++i) { + status = private_f_fss_items_resize(0, &nest->depth[i]); if (F_status_is_error(status)) return status; } // for @@ -192,6 +200,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nests->size; ++i) { + status = private_f_fss_nest_adjust(0, &nests->array[i]); if (F_status_is_error(status)) return status; } // for @@ -218,6 +227,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nests->size; ++i) { + status = private_f_fss_nest_resize(0, &nests->array[i]); if (F_status_is_error(status)) return status; } // for diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index 664d6ef..33a53b8 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -124,7 +124,7 @@ extern "C" { #endif // _di_fl_directory_clone_ /** - * Copy a directory contents, as well as its file mode and possibly the owner and group. + * Copy a directory contents but not the directory itself, as well as its file mode and possibly the owner and group. * * When cloning the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean. * @@ -203,7 +203,7 @@ extern "C" { /** * Copy a directory contents. * - * When copying the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean. + * When copying the contents of a directory but not the directory itself, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean. * * The paths must not contain NULL except for the terminating NULL. * The paths must be NULL terminated. diff --git a/level_1/fl_directory/c/directory/common.h b/level_1/fl_directory/c/directory/common.h index 4079589..de46545 100644 --- a/level_1/fl_directory/c/directory/common.h +++ b/level_1/fl_directory/c/directory/common.h @@ -17,7 +17,7 @@ extern "C" { #endif /** - * An association of a path and a status code. + * A structure containing directory recursion information. * * The allocation macros apply to the path. * diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index f19a48d..440f583 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -790,6 +790,7 @@ extern "C" { #ifndef _di_fl_fss_basic_list_object_write_ f_status_t fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { #ifndef _di_level_1_parameter_checking_ + if (!range) return F_status_set_error(F_parameter); if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index cc568b2..ce7c4e5 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -1240,6 +1240,7 @@ extern "C" { #ifndef _di_fl_fss_embedded_list_object_write_ f_status_t fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { #ifndef _di_level_1_parameter_checking_ + if (!range) return F_status_set_error(F_parameter); if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 8f2bfd5..5376577 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -801,6 +801,7 @@ extern "C" { #ifndef _di_fl_fss_extended_list_object_write_ f_status_t fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { #ifndef _di_level_1_parameter_checking_ + if (!range) return F_status_set_error(F_parameter); if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ diff --git a/level_2/fll_fss/c/fss/payload.c b/level_2/fll_fss/c/fss/payload.c index 4664b46..70b1c9e 100644 --- a/level_2/fll_fss/c/fss/payload.c +++ b/level_2/fll_fss/c/fss/payload.c @@ -72,7 +72,7 @@ extern "C" { if (fl_string_dynamic_partial_compare_string(f_fss_string_payload_s.string, buffer, f_fss_string_payload_s.used, objects->array[objects->used]) == F_equal_to) { status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status)) return status; + if (F_status_is_error(status2)) return status2; contents->array[contents->used].used = 1; contents->array[contents->used].array[0].start = range->start; -- 1.8.3.1