From 9b4d09c6733e088410f1e7b0c1372fd2b8fe182e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 9 Nov 2021 21:58:44 -0600 Subject: [PATCH] Regression: NULL is being printed and fix inline function. The NULL character should not be printed for "safely" print functions. The private inline functions should be made static. --- level_0/f_print/c/print_to.c | 2 +- level_0/f_print/c/private-print.c | 33 ++++++++++++++++++++++++++++++--- level_0/f_print/c/private-print_to.c | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/level_0/f_print/c/print_to.c b/level_0/f_print/c/print_to.c index 59e6e8c..fab6fa8 100644 --- a/level_0/f_print/c/print_to.c +++ b/level_0/f_print/c/print_to.c @@ -14,7 +14,7 @@ extern "C" { * @return * The appropriate status. */ -inline f_status_t private_inline_f_print_to_error() { +static inline f_status_t private_inline_f_print_to_error() { if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); if (errno == EBADF) return F_status_set_error(F_file_descriptor); if (errno == EDESTADDRREQ) return F_status_set_error(F_socket_not); diff --git a/level_0/f_print/c/private-print.c b/level_0/f_print/c/private-print.c index 980c2cb..393124b 100644 --- a/level_0/f_print/c/private-print.c +++ b/level_0/f_print/c/private-print.c @@ -305,7 +305,16 @@ extern "C" { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + return F_status_set_error(F_output); + } + + total = 0; + } + + start = ++i; + continue; } width = macro_f_utf_character_t_width(string[i]); @@ -463,7 +472,16 @@ extern "C" { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + return F_status_set_error(F_output); + } + + total = 0; + } + + start = ++i; + continue; } width = macro_f_utf_character_t_width(string[i]); @@ -592,7 +610,16 @@ extern "C" { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + return F_status_set_error(F_output); + } + + total = 0; + } + + start = ++i; + continue; } width = macro_f_utf_character_t_width(string[i]); diff --git a/level_0/f_print/c/private-print_to.c b/level_0/f_print/c/private-print_to.c index 30d2dce..00c81ce 100644 --- a/level_0/f_print/c/private-print_to.c +++ b/level_0/f_print/c/private-print_to.c @@ -14,7 +14,7 @@ extern "C" { * @return * The appropriate status. */ -inline f_status_t private_inline_f_print_to_error() { +static inline f_status_t private_inline_f_print_to_error() { if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); if (errno == EBADF) return F_status_set_error(F_file_descriptor); if (errno == EDESTADDRREQ) return F_status_set_error(F_socket_not); @@ -218,7 +218,16 @@ inline f_status_t private_inline_f_print_to_error() { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (write(id, string + start, total) == -1) { + return private_inline_f_print_to_error(); + } + + total = 0; + } + + start = ++i; + continue; } if (safe) { @@ -489,7 +498,16 @@ inline f_status_t private_inline_f_print_to_error() { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (write(id, string + start, total) == -1) { + return private_inline_f_print_to_error(); + } + + total = 0; + } + + start = ++i; + continue; } if (safe) { @@ -623,7 +641,16 @@ inline f_status_t private_inline_f_print_to_error() { safe = private_f_print_character_safely_get(string[i]); } else { - safe = 0; + if (total) { + if (write(id, string + start, total) == -1) { + return private_inline_f_print_to_error(); + } + + total = 0; + } + + start = ++i; + continue; } if (safe) { -- 1.8.3.1