From cfbb6ee6885b39ff96d9fc25784c746adf7b353c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 5 May 2021 00:00:40 -0500 Subject: [PATCH] Bugfix: UTF-8 characters buffer is incorrectly returning an error. The previous commit: "Bugfix: UTF-8 characters are not being fully printed" exposed that for UTF-8 characters (width 2 or greater), an error is always returned. When the width properly fits in the requested range, return the appropriate success code instead of an error. --- level_0/f_utf/c/utf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/level_0/f_utf/c/utf.c b/level_0/f_utf/c/utf.c index 876c71b..a6e2d86 100644 --- a/level_0/f_utf/c/utf.c +++ b/level_0/f_utf/c/utf.c @@ -23,7 +23,7 @@ extern "C" { width = macro_f_utf_byte_width(buffer.string[range->start - 1]); if (width > range->start) { - if (width > 1) { + if (width > 1 && width > range->start + 1) { return F_status_set_error(F_complete_not_utf_eos); } @@ -57,7 +57,7 @@ extern "C" { width = macro_f_utf_byte_width(buffer.string[range->start]); if (range->start + width > range->stop) { - if (width > 1) { + if (width > 1 && range->start + width > range->stop + 1) { return F_status_set_error(F_complete_not_utf_stop); } @@ -65,7 +65,7 @@ extern "C" { return F_none_stop; } else if (range->start + width >= buffer.used) { - if (width > 1) { + if (width > 1 && range->start + width >= buffer.used + 1) { return F_status_set_error(F_complete_not_utf_eos); } -- 1.8.3.1