From: Kevin Day Date: Sun, 27 Mar 2022 15:19:04 +0000 (-0500) Subject: Bugfix: Incorrectly performing nulless string appends and prepends. X-Git-Tag: 0.5.9~60 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b22fb1dd59e5af2ba6c3726eb9f83479cde90d9e;p=fll Bugfix: Incorrectly performing nulless string appends and prepends. These problems are exposed by the tests that I am writing. The destination->used < length check cannot be performed because of the presence of NULL characters. The nulless versions of the strings may be identical even if their sizes do not match. The only case where this check should still happen is when destination.used is 0. The comparison operator is using the wrong variable in some cases ('j' should be used with 'destination'). Replace uint8_t with f_char_t. Minor updates to the documentation comments. --- diff --git a/level_0/f_string/c/string.c b/level_0/f_string/c/string.c index 0ddd078..e431f9b 100644 --- a/level_0/f_string/c/string.c +++ b/level_0/f_string/c/string.c @@ -72,7 +72,7 @@ extern "C" { return F_data_not; } - if (destination->used < length) { + if (!destination->used) { return private_f_string_append_nulless(source, length, destination); } @@ -240,7 +240,7 @@ extern "C" { continue; } - if (source[i] != destination->string[i]) { + if (source[i] != destination->string[j]) { return private_f_string_prepend(source, length, destination); } @@ -262,7 +262,7 @@ extern "C" { return F_data_not; } - if (destination->used < length) { + if (!destination->used) { return private_f_string_prepend_nulless(source, length, destination); } @@ -283,7 +283,7 @@ extern "C" { continue; } - if (source[i] != destination->string[i]) { + if (source[i] != destination->string[j]) { return private_f_string_prepend_nulless(source, length, destination); } @@ -333,7 +333,7 @@ extern "C" { #endif // _di_f_string_seek_line_ #ifndef _di_f_string_seek_line_to_ - f_status_t f_string_seek_line_to(const f_string_t string, const uint8_t seek_to, f_string_range_t * const range) { + f_status_t f_string_seek_line_to(const f_string_t string, const f_char_t seek_to, f_string_range_t * const range) { #ifndef _di_level_0_parameter_checking_ if (!range) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -360,7 +360,7 @@ extern "C" { #endif // _di_f_string_seek_line_to_ #ifndef _di_f_string_seek_to_ - f_status_t f_string_seek_to(const f_string_t string, const uint8_t seek_to, f_string_range_t * const range) { + f_status_t f_string_seek_to(const f_string_t string, const f_char_t seek_to, f_string_range_t * const range) { #ifndef _di_level_0_parameter_checking_ if (!range) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index 19746fa..7433156 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -398,13 +398,13 @@ extern "C" { * @return * F_none on success. * F_none_eol on success, but stopped at EOL. - * F_none_stop on success, but stopped stop location. + * F_none_stop on success, but stopped at the stop location. * F_data_not_stop if range.start > range.stop. * * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_string_seek_line_to_ - extern f_status_t f_string_seek_line_to(const f_string_t string, const uint8_t seek_to, f_string_range_t * const range); + extern f_status_t f_string_seek_line_to(const f_string_t string, const f_char_t seek_to, f_string_range_t * const range); #endif // _di_f_string_seek_line_to_ /** @@ -420,7 +420,7 @@ extern "C" { * * @return * F_none on success. - * F_none_stop on success, but stopped stop location. + * F_none_stop on success, but stopped at the stop location. * F_data_not_stop if range.start > range.stop. * * F_complete_not_utf (with error bit) if character is an incomplete UTF-8 fragment. @@ -428,7 +428,7 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_string_seek_to_ - extern f_status_t f_string_seek_to(const f_string_t string, const uint8_t seek_to, f_string_range_t * const range); + extern f_status_t f_string_seek_to(const f_string_t string, const f_char_t seek_to, f_string_range_t * const range); #endif // _di_f_string_seek_to_ #ifdef __cplusplus diff --git a/level_0/f_string/c/string/dynamic.c b/level_0/f_string/c/string/dynamic.c index c462b0e..ed363a6 100644 --- a/level_0/f_string/c/string/dynamic.c +++ b/level_0/f_string/c/string/dynamic.c @@ -77,7 +77,7 @@ extern "C" { if (!source.used) return F_data_not; - if (destination->used < source.used) { + if (!destination->used) { return private_f_string_append_nulless(source.string, source.used, destination); } @@ -333,7 +333,7 @@ extern "C" { const f_array_length_t length = range.stop >= source.used ? source.used - range.start : (range.stop - range.start) + 1; - if (destination->used < length) { + if (!destination->used) { return private_f_string_append_nulless(source.string + range.start, length, destination); } @@ -527,7 +527,7 @@ extern "C" { continue; } - if (source.string[i + range.start] != destination->string[i]) { + if (source.string[i + range.start] != destination->string[j]) { return private_f_string_prepend(source.string + range.start, length, destination); } @@ -551,7 +551,7 @@ extern "C" { const f_array_length_t length = range.stop >= source.used ? source.used - range.start : (range.stop - range.start) + 1; - if (destination->used < length) { + if (!destination->used) { return private_f_string_prepend_nulless(source.string + range.start, length, destination); } @@ -572,7 +572,7 @@ extern "C" { continue; } - if (source.string[i + range.start] != destination->string[i]) { + if (source.string[i + range.start] != destination->string[j]) { return private_f_string_prepend_nulless(source.string + range.start, length, destination); } @@ -639,7 +639,7 @@ extern "C" { continue; } - if (source.string[i] != destination->string[i]) { + if (source.string[i] != destination->string[j]) { return private_f_string_prepend(source.string, source.used, destination); } @@ -659,7 +659,7 @@ extern "C" { if (!source.used) return F_data_not; - if (destination->used < source.used) { + if (!destination->used) { return private_f_string_prepend_nulless(source.string, source.used, destination); } @@ -680,7 +680,7 @@ extern "C" { continue; } - if (source.string[i] != destination->string[i]) { + if (source.string[i] != destination->string[j]) { return private_f_string_prepend_nulless(source.string, source.used, destination); }