From 6e51ec3e954a9b57b62fcf2785f29da67ec2e662 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 6 Oct 2021 20:59:38 -0500 Subject: [PATCH] Bugfix: The decimal '.' (0x2e) should not be considered a number. The decimal may be a number character, but the conversion functions are for whole numbers only. Consider the presence of decimals an error. Use the F_number_decimal character to communicate this case. --- level_1/fl_conversion/c/conversion.c | 46 ++++++++++++++++++++++++++++++++++++ level_1/fl_conversion/c/conversion.h | 12 ++++++++++ 2 files changed, 58 insertions(+) diff --git a/level_1/fl_conversion/c/conversion.c b/level_1/fl_conversion/c/conversion.c index b3800e6..e7366f8 100644 --- a/level_1/fl_conversion/c/conversion.c +++ b/level_1/fl_conversion/c/conversion.c @@ -22,6 +22,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_binary(string[i], &digit) == F_none) { if (digits) { ++digits; @@ -82,6 +86,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_binary(string[i], &digit) == F_none) { if (digits) { ++digits; @@ -126,6 +134,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_decimal(string[i], &digit) == F_none) { if (digits) { @@ -191,6 +203,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_decimal(string[i], &digit) == F_none) { if (digits) { @@ -238,6 +254,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_duodecimal(string[i], &digit) == F_none) { if (digits) { @@ -303,6 +323,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_duodecimal(string[i], &digit) == F_none) { if (digits) { @@ -350,6 +374,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_hexidecimal(string[i], &digit) == F_none) { if (digits) { @@ -415,6 +443,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_hexidecimal(string[i], &digit) == F_none) { if (digits) { @@ -462,6 +494,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_octal(string[i], &digit) == F_none) { if (digits) { @@ -527,6 +563,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { + if (string[i] == 0x2e) { + return F_status_set_error(F_number_decimal); + } + if (f_conversion_character_to_octal(string[i], &digit) == F_none) { if (digits) { @@ -646,6 +686,9 @@ extern "C" { mode = 2; offset += 2; } + else if (string[j] == 0x2e) { + return F_status_set_error(F_number_decimal); + } else { return F_status_set_error(F_number); } @@ -805,6 +848,9 @@ extern "C" { mode = 2; offset += 2; } + else if (string[j] == 0x2e) { + return F_status_set_error(F_number_decimal); + } else { return F_status_set_error(F_number); } diff --git a/level_1/fl_conversion/c/conversion.h b/level_1/fl_conversion/c/conversion.h index 0027652..f1b1c39 100644 --- a/level_1/fl_conversion/c/conversion.h +++ b/level_1/fl_conversion/c/conversion.h @@ -48,6 +48,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-binary values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_number_underflow (with error bit) on integer underflow. * F_parameter (with error bit) if a parameter is invalid. @@ -76,6 +77,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-binary values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -105,6 +107,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-decimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_number_underflow (with error bit) on integer underflow. * F_parameter (with error bit) if a parameter is invalid. @@ -133,6 +136,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-decimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -162,6 +166,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-duodecimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_number_underflow (with error bit) on integer underflow. * F_parameter (with error bit) if a parameter is invalid. @@ -190,6 +195,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-duodecimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -219,6 +225,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-hexidecimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_number_underflow (with error bit) on integer underflow. * F_parameter (with error bit) if a parameter is invalid. @@ -247,6 +254,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-hexidecimal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -276,6 +284,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-octal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -303,6 +312,7 @@ extern "C" { * F_data_not if string starts with a null (length is 0). * * F_number (with error bit) if no conversion was made due to non-octal values being found. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. */ @@ -343,6 +353,7 @@ extern "C" { * * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. * F_number (with error bit) if parameter is not a number. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_overflow (with error bit) on integer overflow. * F_number_underflow (with error bit) on integer underflow. * F_parameter (with error bit) if a parameter is invalid. @@ -387,6 +398,7 @@ extern "C" { * * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. * F_number (with error bit) if parameter is not a number. + * F_number_decimal (with error bit) if number has a decimal digit. * F_number_negative (with error bit) on negative value. * F_number_positive (with error bit) on positive value (has a +, such as '+1', when only '1' is valid here). * F_number_overflow (with error bit) on integer overflow. -- 1.8.3.1