From: Kevin Day Date: Fri, 12 Jun 2020 02:49:46 +0000 (-0500) Subject: Progress: UTF-8 file write should handle case where expanded character is larger... X-Git-Tag: 0.5.0~165 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=e0c09a237c64edcae30b0eedecb2b47a522abe1a;p=fll Progress: UTF-8 file write should handle case where expanded character is larger than write max When the 4-byte wide UTF-8 character is expanded into potentally 4 1-byte wide UTF-8 characters, the available bytes being expanded need to fit in the output buffer. --- diff --git a/level_1/fl_utf_file/c/private-utf_file.c b/level_1/fl_utf_file/c/private-utf_file.c index fb91462..fa8688b 100644 --- a/level_1/fl_utf_file/c/private-utf_file.c +++ b/level_1/fl_utf_file/c/private-utf_file.c @@ -121,6 +121,10 @@ extern "C" { width = f_macro_utf_character_width(string[*written + i]); width_written = width; + if (*written + width > write_max) { + return F_incomplete_utf_stop; + } + buffer_write[used] = f_macro_utf_character_to_char_1(string[*written + i]); if (width > 1) { diff --git a/level_1/fl_utf_file/c/private-utf_file.h b/level_1/fl_utf_file/c/private-utf_file.h index 2894de3..40ed82a 100644 --- a/level_1/fl_utf_file/c/private-utf_file.h +++ b/level_1/fl_utf_file/c/private-utf_file.h @@ -62,6 +62,7 @@ extern "C" { * F_none on success. * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). + * F_incomplete_utf_stop if max write was reached but was unable to completely write a given UTF-8 block (incomplete UTF-8 is not written, not even partially). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. * F_file_closed (with error bit) if file is not open. diff --git a/level_1/fl_utf_file/c/utf_file.h b/level_1/fl_utf_file/c/utf_file.h index 6501ab1..91ff1da 100644 --- a/level_1/fl_utf_file/c/utf_file.h +++ b/level_1/fl_utf_file/c/utf_file.h @@ -139,6 +139,7 @@ extern "C" { * F_none on success. * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). + * F_incomplete_utf_stop if max write was reached but was unable to completely write a given UTF-8 block (incomplete UTF-8 is not written, not even partially). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. * F_file (with error bit) if file descriptor is in an error state. @@ -172,6 +173,7 @@ extern "C" { * F_none on success. * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). + * F_incomplete_utf_stop if max write was reached but was unable to completely write a given UTF-8 block (incomplete UTF-8 is not written, not even partially). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. * F_file (with error bit) if file descriptor is in an error state. @@ -205,6 +207,7 @@ extern "C" { * F_none on success. * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). + * F_incomplete_utf_stop if max write was reached but was unable to completely write a given UTF-8 block (incomplete UTF-8 is not written, not even partially). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. * F_file (with error bit) if file descriptor is in an error state. @@ -238,6 +241,7 @@ extern "C" { * F_none on success. * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). + * F_incomplete_utf_stop if max write was reached but was unable to completely write a given UTF-8 block (incomplete UTF-8 is not written, not even partially). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. * F_file (with error bit) if file descriptor is in an error state.