From 98796caf950ea72776f6985d10e2d13c0942718e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 3 May 2020 21:43:05 -0500 Subject: [PATCH] Update: ensure f_no_data is returned when applicable for fl_string and fl_utf functions --- level_1/fl_string/c/private-string.c | 11 +++++++++++ level_1/fl_string/c/private-string.h | 1 + level_1/fl_string/c/string.c | 2 ++ level_1/fl_utf/c/private-utf.c | 11 +++++++++++ level_1/fl_utf/c/private-utf.h | 1 + level_1/fl_utf/c/utf.c | 2 ++ 6 files changed, 28 insertions(+) diff --git a/level_1/fl_string/c/private-string.c b/level_1/fl_string/c/private-string.c index 5f4f931..2b62f19 100644 --- a/level_1/fl_string/c/private-string.c +++ b/level_1/fl_string/c/private-string.c @@ -411,6 +411,17 @@ extern "C" { if (status == f_false) break; } // for + if (*stop == *start) { + status = f_utf_is_whitespace(source + *stop, (stop_original - *stop) + 1); + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_maybe) return f_status_set_error(f_invalid_utf); + + return status; + } + + if (status == f_true) return f_no_data; + } + return f_none; } #endif // !defined(_di_fl_string_rip_) || !defined(_di_fl_string_dynamic_rip_) || !defined(_di_fl_string_rip_nulless_) || !defined(_di_fl_string_dynamic_rip_nulless_) diff --git a/level_1/fl_string/c/private-string.h b/level_1/fl_string/c/private-string.h index 77994d7..1c7ee77 100644 --- a/level_1/fl_string/c/private-string.h +++ b/level_1/fl_string/c/private-string.h @@ -211,6 +211,7 @@ extern "C" { * * @return * f_none on success. + * f_no_data on success but only whitespace found. * f_invalid_parameter (with error bit) if a parameter is invalid. * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index e59f5e8..9d61eba 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -652,6 +652,7 @@ extern "C" { f_status status = private_fl_string_rip_find_range(source, &begin, &end); if (f_status_is_error(status)) return status; + if (status == f_no_data) return status; return private_fl_string_append(source, begin, end, destination); } @@ -670,6 +671,7 @@ extern "C" { f_status status = private_fl_string_rip_find_range(source, &begin, &end); if (f_status_is_error(status)) return status; + if (status == f_no_data) return status; return private_fl_string_append_nulless(source, begin, end, destination); } diff --git a/level_1/fl_utf/c/private-utf.c b/level_1/fl_utf/c/private-utf.c index cfd223a..48b10ec 100644 --- a/level_1/fl_utf/c/private-utf.c +++ b/level_1/fl_utf/c/private-utf.c @@ -378,6 +378,17 @@ extern "C" { if (status == f_false) break; } // for + if (*stop == *start) { + status = f_utf_character_is_whitespace(source[*stop]); + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_maybe) return f_status_set_error(f_invalid_utf); + + return status; + } + + if (status == f_true) return f_no_data; + } + return f_none; } #endif // !defined(_di_fl_utf_string_rip_) || !defined(_di_fl_utf_string_dynamic_rip_) || !defined(_di_fl_utf_string_rip_nulless_) || !defined(_di_fl_utf_string_dynamic_rip_nulless_) diff --git a/level_1/fl_utf/c/private-utf.h b/level_1/fl_utf/c/private-utf.h index 6e0d215..a2417f0 100644 --- a/level_1/fl_utf/c/private-utf.h +++ b/level_1/fl_utf/c/private-utf.h @@ -211,6 +211,7 @@ extern "C" { * * @return * f_none on success. + * f_no_data on success but only whitespace found. * f_invalid_parameter (with error bit) if a parameter is invalid. * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. diff --git a/level_1/fl_utf/c/utf.c b/level_1/fl_utf/c/utf.c index 1e9ef87..9bf9443 100644 --- a/level_1/fl_utf/c/utf.c +++ b/level_1/fl_utf/c/utf.c @@ -562,6 +562,7 @@ extern "C" { f_status status = private_fl_utf_string_rip_find_range(source, &begin, &end); if (f_status_is_error(status)) return status; + if (status == f_no_data) return status; return private_fl_utf_string_append(source, begin, end, destination); } @@ -580,6 +581,7 @@ extern "C" { f_status status = private_fl_utf_string_rip_find_range(source, &begin, &end); if (f_status_is_error(status)) return status; + if (status == f_no_data) return status; return private_fl_utf_string_append_nulless(source, begin, end, destination); } -- 1.8.3.1