From: Kevin Day Date: Sat, 25 Apr 2020 00:39:35 +0000 (-0500) Subject: Feature: add f_string_length_size max of (uint64_t - 4) X-Git-Tag: 0.5.0~338 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=72e8e5fd5f97302bc8faa7f0a06614ef9d24fa63;p=fll Feature: add f_string_length_size max of (uint64_t - 4) The goal here is that any string processing must be able to add a given UTF-8 width (4-byte) and not oveflow. Much of the code in this project will not check this as it should be done so at a higher level (performance reasons). The ideal time is that when allocating some string, always allocate at max f_string_length_size. --- diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index 51c23eb..b3ac568 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -6,6 +6,9 @@ * Licenses: lgplv2.1 * * Provides string capabilities. + * + * It is highly recommended that all string arrays are set to a max size of f_string_length_size. + * Any calculations against the length (aka: string.used) can always perform (A < B) operators such that the B is f_string_length_size + 1 without integer overflow. */ #ifndef _F_string_h #define _F_string_h @@ -99,6 +102,10 @@ extern "C" { #ifndef _di_f_string_length_ typedef f_number_unsigned f_string_length; + // string size is set to (size - 4) to compensate for UTF-8 4-byte character such that it can easily act as a (size - 1) regardless of UTF-8. + #define f_string_length_size 0xfffffffffffffffb + #define f_string_length_size_max f_type_size_max_64_positive + #define f_string_length_printf string_format_long_integer #define f_macro_string_length_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_string_length), length)