From: Kevin Day Date: Sun, 19 Dec 2021 02:21:56 +0000 (-0600) Subject: Bugfix: Incorrect return values in some print functions. X-Git-Tag: 0.5.7~23 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ac25ff9ebaf4dcac41edc8847f212f75139a9aa3;p=fll Bugfix: Incorrect return values in some print functions. These are expecting status to be returned. Update the documentation. --- diff --git a/level_1/fl_print/c/print.c b/level_1/fl_print/c/print.c index c4e45a8..3350a62 100644 --- a/level_1/fl_print/c/print.c +++ b/level_1/fl_print/c/print.c @@ -8,8 +8,8 @@ extern "C" { #ifndef _di_fl_print_format_ f_status_t fl_print_format(const f_string_t string, FILE *stream, ...) { #ifndef _di_level_1_parameter_checking_ - if (!string) return 0; - if (!stream) return 0; + if (!string) return F_status_set_error(F_parameter); + if (!stream) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = F_none; @@ -18,10 +18,10 @@ extern "C" { va_start(ap, stream); - for (f_string_t current = string; *current; current += 1) { + for (f_string_t current = string; *current; ++current) { if (*current == f_string_ascii_percent_s[0]) { - current += 1; + ++current; current = private_fl_print_format_convert(current, stream, &ap, &status); if (F_status_is_error(status)) break; @@ -35,7 +35,9 @@ extern "C" { va_end(ap); - return status; + if (F_status_is_error(status)) return status; + + return F_none; } #endif // _di_fl_print_format_ @@ -53,17 +55,17 @@ extern "C" { #ifndef _di_fl_print_string_va_ f_status_t fl_print_string_va(const f_string_t string, FILE *stream, va_list *ap) { #ifndef _di_level_1_parameter_checking_ - if (!string) return 0; - if (!stream) return 0; - if (!ap) return 0; + if (!string) return F_status_set_error(F_parameter); + if (!stream) return F_status_set_error(F_parameter); + if (!ap) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = F_none; - for (f_string_t current = string; *current; current += 1) { + for (f_string_t current = string; *current; ++current) { if (*current == f_string_ascii_percent_s[0]) { - current += 1; + ++current; current = private_fl_print_format_convert(current, stream, ap, &status); if (F_status_is_error(status)) break; @@ -75,7 +77,9 @@ extern "C" { } } // for - return status; + if (F_status_is_error(status)) return status; + + return F_none; } #endif // _di_fl_print_string_va_ diff --git a/level_1/fl_print/c/print.h b/level_1/fl_print/c/print.h index 82c8c62..9371df9 100644 --- a/level_1/fl_print/c/print.h +++ b/level_1/fl_print/c/print.h @@ -191,8 +191,20 @@ extern "C" { * Additional arguments relating to the string. * * @return - * The number of 1-byte characters processed from the string. - * Any error will will result in the current count at the time of the error to be returned. + * F_none on success. + * + * F_eos (with error bit) on EOS reached. + * F_output (with error bit) on failure to print to the output file. + * F_parameter (with error bit) if a parameter is invalid. + * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). + * + * Errors (with error bit) from: f_conversion_number_signed_print(). + * Errors (with error bit) from: f_conversion_number_unsigned_print(). + * Errors (with error bit) from: f_print_dynamic(). + * Errors (with error bit) from: f_print_dynamic_raw(). + * Errors (with error bit) from: f_print_dynamic_safely(). + * Errors (with error bit) from: f_print_safely(). + * Errors (with error bit) from: f_print_terminated(). * * @see fprintf() * @see fputc_unlocked() @@ -289,15 +301,11 @@ extern "C" { * @return * F_none on success. * + * F_eos (with error bit) on EOS reached. * F_output (with error bit) on failure to print to the output file. + * F_parameter (with error bit) if a parameter is invalid. * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). * - * Success from: f_print_dynamic(). - * Success from: f_print_dynamic_raw(). - * Success from: f_print_dynamic_safely(). - * Success from: f_print_safely(). - * Success from: f_print_terminated(). - * * Errors (with error bit) from: f_conversion_number_signed_print(). * Errors (with error bit) from: f_conversion_number_unsigned_print(). * Errors (with error bit) from: f_print_dynamic().