From 0078cfad8ff4cac0d7ecdd85c31290514217d0cb Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 31 May 2021 00:02:58 -0500 Subject: [PATCH] Update: Attempt to avoid libc/POSIX character array length limitations. Define f_string_t_length to handle the special case max length. Make the f_utf_string_t also operate in the same way (even it it might avoid the problem by being a different type than char). The f_utf_string_t is changed in this way for consistency reasons. --- level_0/f_capability/c/capability.c | 4 ++-- level_0/f_console/c/console-common.h | 2 +- level_0/f_environment/c/environment-common.h | 2 +- level_0/f_file/c/file.c | 16 ++++++++-------- level_0/f_string/c/private-string.c | 8 ++++---- level_0/f_string/c/string-common.h | 9 +++++++++ level_0/f_string/c/string_dynamic.c | 10 +++++----- level_0/f_utf/c/private-utf.c | 8 ++++---- level_0/f_utf/c/utf_dynamic.c | 10 +++++----- level_1/fl_directory/c/private-directory.c | 12 ++++++------ level_1/fl_utf_file/c/utf_file.c | 6 +++--- level_2/fll_fss/c/fss_basic.c | 2 +- level_2/fll_fss/c/fss_basic_list.c | 2 +- level_2/fll_fss/c/fss_embedded_list.c | 2 +- level_2/fll_fss/c/fss_extended.c | 2 +- level_2/fll_fss/c/fss_extended_list.c | 2 +- level_2/fll_path/c/path.h | 2 +- level_3/fake/c/private-build.c | 2 +- 18 files changed, 55 insertions(+), 46 deletions(-) diff --git a/level_0/f_capability/c/capability.c b/level_0/f_capability/c/capability.c index bdb0644..d00e4fe 100644 --- a/level_0/f_capability/c/capability.c +++ b/level_0/f_capability/c/capability.c @@ -1047,7 +1047,7 @@ extern "C" { const f_array_length_t length = strlen(result); if (name->used + length + 1 > name->size) { - if (name->used + length + 1 > f_array_length_t_size) { + if (name->used + length + 1 > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1088,7 +1088,7 @@ extern "C" { if (result) { if (text->used + length + 1 > text->size) { - if (text->used + length + 1 > f_array_length_t_size) { + if (text->used + length + 1 > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_0/f_console/c/console-common.h b/level_0/f_console/c/console-common.h index 3ae9994..cf00545 100644 --- a/level_0/f_console/c/console-common.h +++ b/level_0/f_console/c/console-common.h @@ -173,7 +173,7 @@ extern "C" { * However, the libc/POSIX appears to limit this to 2^63 (signed). */ #ifndef _di_f_console_length_size_ - #define f_console_parameter_size f_type_size_max_64_positive + #define f_console_parameter_size f_string_t_size #endif // _di_f_console_length_size_ /** diff --git a/level_0/f_environment/c/environment-common.h b/level_0/f_environment/c/environment-common.h index ac0af36..ef70835 100644 --- a/level_0/f_environment/c/environment-common.h +++ b/level_0/f_environment/c/environment-common.h @@ -20,7 +20,7 @@ extern "C" { * Environment related defines. */ #ifndef _di_f_environment_defines_ - #define f_environment_max_length f_array_length_t_size + #define f_environment_max_length f_string_t_size #endif // _di_f_environment_defines_ #ifdef __cplusplus diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 62501a0..123e6b5 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -1315,7 +1315,7 @@ extern "C" { f_array_length_t size = strnlen(path_to_name, length); if (name_base->used + size > name_base->size) { - if (name_base->used + size > f_array_length_t_size) { + if (name_base->used + size > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1351,7 +1351,7 @@ extern "C" { f_array_length_t size = strnlen(path_to_name, length); if (name_directory->used + size > name_directory->size) { - if (name_directory->used + size > f_array_length_t_size) { + if (name_directory->used + size > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1428,7 +1428,7 @@ extern "C" { for (f_string_t buffer_read = 0; ; ) { if (buffer->used + file.size_read > buffer->size) { - if (buffer->size + file.size_read > f_array_length_t_size) { + if (buffer->size + file.size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1478,7 +1478,7 @@ extern "C" { f_string_t buffer_read = 0; if (buffer->used + file.size_read > buffer->size) { - if (buffer->size + file.size_read > f_array_length_t_size) { + if (buffer->size + file.size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1538,7 +1538,7 @@ extern "C" { } if (buffer->used + buffer_size > buffer->size) { - if (buffer->size + buffer_size > f_array_length_t_size) { + if (buffer->size + buffer_size > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -1997,7 +1997,7 @@ extern "C" { for (;;) { if (buffer->used + file.size_read > buffer->size) { - if (buffer->size + file.size_read > f_array_length_t_size) { + if (buffer->size + file.size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -2043,7 +2043,7 @@ extern "C" { ssize_t size_read = 0; if (buffer->used + file.size_read > buffer->size) { - if (buffer->size + file.size_read > f_array_length_t_size) { + if (buffer->size + file.size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -2097,7 +2097,7 @@ extern "C" { } if (buffer->used + buffer_size > buffer->size) { - if (buffer->size + buffer_size > f_array_length_t_size) { + if (buffer->size + buffer_size > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_0/f_string/c/private-string.c b/level_0/f_string/c/private-string.c index e863f3b..63cb1b0 100644 --- a/level_0/f_string/c/private-string.c +++ b/level_0/f_string/c/private-string.c @@ -23,7 +23,7 @@ extern "C" { #if !defined(_di_f_string_append_assure_nulless_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_assure_nulless_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(_di_f_string_dynamic_partial_append_assure_nulless_) || !defined(_di_f_string_dynamic_partial_append_nulless_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_mash_nulless_) f_status_t private_f_string_append_nulless(const f_string_t source, const f_array_length_t length, f_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -93,7 +93,7 @@ extern "C" { f_status_t private_f_string_dynamic_increase_by(const f_array_length_t amount, f_string_dynamic_t *dynamic) { if (dynamic->used + amount > dynamic->size) { - if (dynamic->used + amount > f_array_length_t_size) { + if (dynamic->used + amount > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -333,7 +333,7 @@ extern "C" { #if !defined(_di_f_string_dynamic_mish_) || !defined(_di_f_string_dynamic_partial_mish_) || !defined(_di_f_string_dynamic_partial_prepend_assure_) || !defined(_di_f_string_dynamic_partial_prepend_) || !defined(_di_f_string_dynamic_prepend_assure_) || !defined(_di_f_string_dynamic_prepend_) || !defined(_di_f_string_mish_) || !defined(_di_f_string_prepend_assure_) || !defined(_di_f_string_prepend_) f_status_t private_f_string_prepend(const f_string_t source, const f_array_length_t length, f_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -358,7 +358,7 @@ extern "C" { #if !defined(_di_f_string_dynamic_mish_nulless_) || !defined(_di_f_string_dynamic_partial_mish_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_assure_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_nulless_) || !defined(_di_f_string_dynamic_prepend_assure_nulless_) || !defined(_di_f_string_dynamic_prepend_nulless_) || !defined(_di_f_string_mish_nulless_) || !defined(_di_f_string_prepend_assure_nulless_) || !defined(_di_f_string_prepend_nulless_) f_status_t private_f_string_prepend_nulless(const f_string_t source, const f_array_length_t length, f_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h index de0adfe..dabd4b0 100644 --- a/level_0/f_string/c/string-common.h +++ b/level_0/f_string/c/string-common.h @@ -28,6 +28,12 @@ extern "C" { * Define the basic string type. * * Dynamic allocation macros are provided, but it is recommended to utilize the f_string_dynamic_t for dynamic allocation. + * + * is provided as a way t have a string max for systems that do not support max string length in 64-bits (when f_array_length_t is set to uint64_t). + * + * The ideal length for a string is f_array_length_t_size, which generally defaults to 2^64 (unsigned). + * However, the libc/POSIX appears to limit this to 2^63 (signed). + * f_string_t_size is provided to help safely navigate this. */ #ifndef _di_f_string_t_ typedef char *f_string_t; @@ -41,6 +47,9 @@ extern "C" { #define macro_f_string_t_delete_simple(string, length) f_memory_resize(length, 0, sizeof(f_string_t), (void **) & string); #define macro_f_string_t_destroy_simple(string, length) f_memory_adjust(length, 0, sizeof(f_string_t), (void **) & string); + + // @fixme update all code utilizing f_array_length_t on a string, such as strnlen(). + #define f_string_t_size f_type_size_64_positive #endif // _di_f_string_t_ /** diff --git a/level_0/f_string/c/string_dynamic.c b/level_0/f_string/c/string_dynamic.c index 21f26f9..10f2192 100644 --- a/level_0/f_string/c/string_dynamic.c +++ b/level_0/f_string/c/string_dynamic.c @@ -173,12 +173,12 @@ extern "C" { if (dynamic->used + 1 > dynamic->size) { f_array_length_t size = dynamic->used + step; - if (size > f_array_length_t_size) { - if (dynamic->used + 1 > f_array_length_t_size) { + if (size > f_string_t_size) { + if (dynamic->used + 1 > f_string_t_size) { return F_status_set_error(F_string_too_large); } - size = f_array_length_t_size; + size = f_string_t_size; } return private_f_string_dynamic_resize(size, dynamic); @@ -843,7 +843,7 @@ extern "C" { return F_none; } - if (destination->used == f_array_length_t_size) { + if (destination->used == f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -876,7 +876,7 @@ extern "C" { } // for } - if (destination->used == f_array_length_t_size) { + if (destination->used == f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_0/f_utf/c/private-utf.c b/level_0/f_utf/c/private-utf.c index 52d8f64..76f0a5d 100644 --- a/level_0/f_utf/c/private-utf.c +++ b/level_0/f_utf/c/private-utf.c @@ -2270,7 +2270,7 @@ extern "C" { #if !defined(_di_f_utf_string_append_assure_nulless_) || !defined(_di_f_utf_string_append_nulless_) || !defined(_di_f_utf_string_dynamic_append_assure_nulless_) || !defined(_di_f_utf_string_dynamic_append_nulless_) || !defined(_di_f_utf_string_dynamic_mash_nulless_) || !defined(_di_f_utf_string_dynamic_partial_append_assure_nulless_) || !defined(_di_f_utf_string_dynamic_partial_append_nulless_) || !defined(_di_f_utf_string_dynamic_partial_mash_nulless_) || !defined(_di_f_utf_string_mash_nulless_) f_status_t private_f_utf_string_append_nulless(const f_utf_string_t source, const f_array_length_t length, f_utf_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -2340,7 +2340,7 @@ extern "C" { f_status_t private_f_utf_string_dynamic_increase_by(const f_array_length_t amount, f_utf_string_dynamic_t *dynamic) { if (dynamic->used + amount > dynamic->size) { - if (dynamic->used + amount > f_array_length_t_size) { + if (dynamic->used + amount > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -2579,7 +2579,7 @@ extern "C" { #if !defined(_di_f_utf_string_dynamic_mish_) || !defined(_di_f_utf_string_dynamic_partial_mish_) || !defined(_di_f_utf_string_dynamic_partial_prepend_assure_) || !defined(_di_f_utf_string_dynamic_partial_prepend_) || !defined(_di_f_utf_string_dynamic_prepend_assure_) || !defined(_di_f_utf_string_dynamic_prepend_) || !defined(_di_f_utf_string_mish_) || !defined(_di_f_utf_string_prepend_assure_) || !defined(_di_f_utf_string_prepend_) f_status_t private_f_utf_string_prepend(const f_utf_string_t source, const f_array_length_t length, f_utf_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -2604,7 +2604,7 @@ extern "C" { #if !defined(_di_f_utf_string_dynamic_mish_nulless_) || !defined(_di_f_utf_string_dynamic_partial_mish_nulless_) || !defined(_di_f_utf_string_dynamic_partial_prepend_assure_nulless_) || !defined(_di_f_utf_string_dynamic_partial_prepend_nulless_) || !defined(_di_f_utf_string_dynamic_prepend_assure_nulless_) || !defined(_di_f_utf_string_dynamic_prepend_nulless_) || !defined(_di_f_utf_string_mish_nulless_) || !defined(_di_f_utf_string_prepend_assure_nulless_) || !defined(_di_f_utf_string_prepend_nulless_) f_status_t private_f_utf_string_prepend_nulless(const f_utf_string_t source, const f_array_length_t length, f_utf_string_dynamic_t *destination) { - if (destination->used + length > f_array_length_t_size) { + if (destination->used + length > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_0/f_utf/c/utf_dynamic.c b/level_0/f_utf/c/utf_dynamic.c index 66fa497..dece63d 100644 --- a/level_0/f_utf/c/utf_dynamic.c +++ b/level_0/f_utf/c/utf_dynamic.c @@ -166,12 +166,12 @@ extern "C" { if (dynamic->used + 1 > dynamic->size) { f_array_length_t size = dynamic->used + step; - if (size > f_array_length_t_size) { - if (dynamic->used + 1 > f_array_length_t_size) { + if (size > f_string_t_size) { + if (dynamic->used + 1 > f_string_t_size) { return F_status_set_error(F_string_too_large); } - size = f_array_length_t_size; + size = f_string_t_size; } return private_f_utf_string_dynamic_resize(size, dynamic); @@ -835,7 +835,7 @@ extern "C" { return F_none; } - if (destination->used == f_array_length_t_size) { + if (destination->used == f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -868,7 +868,7 @@ extern "C" { } // for } - if (destination->used == f_array_length_t_size) { + if (destination->used == f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 91868d6..0ce4b7a 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -178,7 +178,7 @@ extern "C" { status = f_file_stat(source.string, F_false, &source_stat); if (F_status_is_error(status)) { if (status == F_status_set_error(F_string_too_large)) { - size = f_array_length_t_size - 1; + size = f_string_t_size - 1; } else { size = source.used + file.used + 1; @@ -192,7 +192,7 @@ extern "C" { } else { if (status == F_status_set_error(F_string_too_large)) { - size = f_array_length_t_size - 1; + size = f_string_t_size - 1; } else { size = destination.used + file.used + 1; @@ -384,7 +384,7 @@ extern "C" { if (F_status_is_error(status)) { if (status == F_status_set_error(F_string_too_large)) { - size = f_array_length_t_size - 1; + size = f_string_t_size - 1; } else { size = source.used + file.used + 1; @@ -398,7 +398,7 @@ extern "C" { } else { if (status == F_status_set_error(F_string_too_large)) { - size = f_array_length_t_size - 1; + size = f_string_t_size - 1; } else { size = destination.used + file.used + 1; @@ -551,7 +551,7 @@ extern "C" { if (F_status_is_error(status)) break; if (names->array[names->used].used > 0 && names->array[names->used].string[names->array[names->used].used - 1] != 0) { - if (names->array[names->used].used == f_array_length_t_size) { + if (names->array[names->used].used == f_string_t_size) { status = F_status_set_error(F_string_too_large); break; } @@ -766,7 +766,7 @@ extern "C" { total += length_truncated - start; if (destination->used + total > destination->size) { - if (destination->used + total > f_array_length_t_size) { + if (destination->used + total > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_1/fl_utf_file/c/utf_file.c b/level_1/fl_utf_file/c/utf_file.c index 924bf2a..19845dd 100644 --- a/level_1/fl_utf_file/c/utf_file.c +++ b/level_1/fl_utf_file/c/utf_file.c @@ -34,7 +34,7 @@ extern "C" { while ((size_read = read(file.id, buffer_read, file.size_read)) > 0) { if (buffer->used + size_read > buffer->size) { - if (buffer->size + size_read > f_array_length_t_size) { + if (buffer->size + size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -94,7 +94,7 @@ extern "C" { if ((size_read = read(file.id, buffer_read, file.size_read)) > 0) { if (buffer->used + size_read > buffer->size) { - if (buffer->size + size_read > f_array_length_t_size) { + if (buffer->size + size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } @@ -167,7 +167,7 @@ extern "C" { while (buffer_count < total && (size_read = read(file.id, buffer_read, buffer_size)) > 0) { if (buffer->used + size_read > buffer->size) { - if (buffer->size + size_read > f_array_length_t_size) { + if (buffer->size + size_read > f_string_t_size) { return F_status_set_error(F_string_too_large); } diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index fbf8079..ee9db57 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -147,7 +147,7 @@ extern "C" { objects_quoted->used++; } - } while (range->start < f_array_length_t_size); + } while (range->start < f_string_t_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index eac9b57..6b125f8 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -121,7 +121,7 @@ extern "C" { objects->used++; contents->used++; - } while (range->start < f_array_length_t_size); + } while (range->start < f_string_t_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_embedded_list.c b/level_2/fll_fss/c/fss_embedded_list.c index bed51a3..bbd2fc5 100644 --- a/level_2/fll_fss/c/fss_embedded_list.c +++ b/level_2/fll_fss/c/fss_embedded_list.c @@ -119,7 +119,7 @@ extern "C" { return F_none_stop; } - } while (range->start < f_array_length_t_size); + } while (range->start < f_string_t_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 9e9bd96..8db3822 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -186,7 +186,7 @@ extern "C" { contents_quoted->used++; } - } while (range->start < f_array_length_t_size); + } while (range->start < f_string_t_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_extended_list.c b/level_2/fll_fss/c/fss_extended_list.c index 5769800..6f5bee3 100644 --- a/level_2/fll_fss/c/fss_extended_list.c +++ b/level_2/fll_fss/c/fss_extended_list.c @@ -121,7 +121,7 @@ extern "C" { objects->used++; contents->used++; - } while (range->start < f_array_length_t_size); + } while (range->start < f_string_t_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_path/c/path.h b/level_2/fll_path/c/path.h index b6839c3..b1920b8 100644 --- a/level_2/fll_path/c/path.h +++ b/level_2/fll_path/c/path.h @@ -33,7 +33,7 @@ extern "C" { * This does not check if the path exists or not. * This processes the relative parts: './', '../', and extra '/'. * This does not process symbolic links. - * This has a max size of f_array_length_t_size. + * This has a max size of f_string_t_size. * * @param path * The source path to determine what the canonical path is. diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index 5c666e4..568d9da 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -1289,7 +1289,7 @@ extern "C" { } if (environment->used + data_build.setting.environment.used > environment->size) { - if (environment->used + data_build.setting.environment.used > f_array_length_t_size) { + if (environment->used + data_build.setting.environment.used > f_environment_max_length) { if (main.error.verbosity != f_console_verbosity_quiet) { fprintf(main.error.to.stream, "%c", f_string_eol_s[0]); f_color_print(main.error.to.stream, main.context.set.error, "%sThe values for the setting '", fll_error_print_error); -- 1.8.3.1