From 6f9b00200cb46aa0cc02efdd234227748a0b3bce Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 13 Jun 2020 16:37:55 -0500 Subject: [PATCH] Bugfix: incorrect invalid parameter check for file write for used to size comparison The used may equal size, do not trigger an error. Change un-reallocated dynamic strings to static strings. --- level_0/f_file/c/file.c | 16 ++++++++-------- level_0/f_file/c/file.h | 8 ++++---- level_1/fl_utf_file/c/utf_file.c | 16 ++++++++-------- level_1/fl_utf_file/c/utf_file.h | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 837beed..406efaf 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -1079,10 +1079,10 @@ extern "C" { #endif // _di_f_file_touch_at_ #ifndef _di_f_file_write_ - f_return_status f_file_write(const f_file file, const f_string_dynamic buffer, f_string_length *written) { + f_return_status f_file_write(const f_file file, const f_string_static buffer, f_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -1115,10 +1115,10 @@ extern "C" { #endif // _di_f_file_write_ #ifndef _di_f_file_write_block_ - f_return_status f_file_write_block(const f_file file, const f_string_dynamic buffer, f_string_length *written) { + f_return_status f_file_write_block(const f_file file, const f_string_static buffer, f_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -1161,10 +1161,10 @@ extern "C" { #endif // _di_f_file_write_block_ #ifndef _di_f_file_write_until_ - f_return_status f_file_write_until(const f_file file, const f_string_dynamic buffer, const f_string_length total, f_string_length *written) { + f_return_status f_file_write_until(const f_file file, const f_string_static buffer, const f_string_length total, f_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -1207,10 +1207,10 @@ extern "C" { #endif // _di_f_file_write_until_ #ifndef _di_f_file_write_range_ - f_return_status f_file_write_range(const f_file file, const f_string_dynamic buffer, const f_string_range range, f_string_length *written) { + f_return_status f_file_write_range(const f_file file, const f_string_static buffer, const f_string_range range, f_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); if (range.stop < range.start) return F_status_set_error(F_parameter); if (range.start >= buffer.used) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 778d2aa..07c9d45 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -1695,7 +1695,7 @@ extern "C" { * @see write() */ #ifndef _di_f_file_write_ - extern f_return_status f_file_write(const f_file file, const f_string_dynamic buffer, f_string_length *written); + extern f_return_status f_file_write(const f_file file, const f_string_static buffer, f_string_length *written); #endif // _di_f_file_write_ /** @@ -1811,7 +1811,7 @@ extern "C" { * @see write() */ #ifndef _di_f_file_write_block_ - extern f_return_status f_file_write_block(const f_file file, const f_string_dynamic buffer, f_string_length *written); + extern f_return_status f_file_write_block(const f_file file, const f_string_static buffer, f_string_length *written); #endif // _di_f_file_write_block_ /** @@ -1845,7 +1845,7 @@ extern "C" { * @see write() */ #ifndef _di_f_file_write_until_ - extern f_return_status f_file_write_until(const f_file file, const f_string_dynamic buffer, const f_string_length total, f_string_length *written); + extern f_return_status f_file_write_until(const f_file file, const f_string_static buffer, const f_string_length total, f_string_length *written); #endif // _di_f_file_write_until_ /** @@ -1879,7 +1879,7 @@ extern "C" { * @see write() */ #ifndef _di_f_file_write_range_ - extern f_return_status f_file_write_range(const f_file file, const f_string_dynamic buffer, const f_string_range range, f_string_length *written); + extern f_return_status f_file_write_range(const f_file file, const f_string_static buffer, const f_string_range range, f_string_length *written); #endif // _di_f_file_write_range_ #ifdef __cplusplus diff --git a/level_1/fl_utf_file/c/utf_file.c b/level_1/fl_utf_file/c/utf_file.c index ab84fb8..80aef49 100644 --- a/level_1/fl_utf_file/c/utf_file.c +++ b/level_1/fl_utf_file/c/utf_file.c @@ -193,10 +193,10 @@ extern "C" { #endif // _di_fl_utf_file_read_until_ #ifndef _di_fl_utf_file_write_ - f_return_status fl_utf_file_write(const f_file file, const f_utf_string_dynamic buffer, f_utf_string_length *written) { + f_return_status fl_utf_file_write(const f_file file, const f_utf_string_static buffer, f_utf_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -217,10 +217,10 @@ extern "C" { #endif // _di_fl_utf_file_write_ #ifndef _di_fl_utf_file_write_block_ - f_return_status fl_utf_file_write_block(const f_file file, const f_utf_string_dynamic buffer, f_utf_string_length *written) { + f_return_status fl_utf_file_write_block(const f_file file, const f_utf_string_static buffer, f_utf_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -247,10 +247,10 @@ extern "C" { #endif // _di_fl_utf_file_write_block_ #ifndef _di_fl_utf_file_write_until_ - f_return_status fl_utf_file_write_until(const f_file file, const f_utf_string_dynamic buffer, const f_utf_string_length total, f_utf_string_length *written) { + f_return_status fl_utf_file_write_until(const f_file file, const f_utf_string_static buffer, const f_utf_string_length total, f_utf_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (file.id < 0) return F_status_set_error(F_file); @@ -277,10 +277,10 @@ extern "C" { #endif // _di_fl_utf_file_write_until_ #ifndef _di_fl_utf_file_write_range_ - f_return_status fl_utf_file_write_range(const f_file file, const f_utf_string_dynamic buffer, const f_utf_string_range range, f_utf_string_length *written) { + f_return_status fl_utf_file_write_range(const f_file file, const f_utf_string_static buffer, const f_utf_string_range range, f_utf_string_length *written) { #ifndef _di_level_0_parameter_checking_ if (file.size_write == 0) return F_status_set_error(F_parameter); - if (buffer.used >= buffer.size) return F_status_set_error(F_parameter); + if (buffer.used > buffer.size) return F_status_set_error(F_parameter); if (range.stop < range.start) return F_status_set_error(F_parameter); if (range.start >= buffer.used) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ diff --git a/level_1/fl_utf_file/c/utf_file.h b/level_1/fl_utf_file/c/utf_file.h index 91ff1da..9e47c69 100644 --- a/level_1/fl_utf_file/c/utf_file.h +++ b/level_1/fl_utf_file/c/utf_file.h @@ -153,7 +153,7 @@ extern "C" { * @see write() */ #ifndef _di_fl_utf_file_write_ - extern f_return_status fl_utf_file_write(const f_file file, const f_utf_string_dynamic buffer, f_utf_string_length *written); + extern f_return_status fl_utf_file_write(const f_file file, const f_utf_string_static buffer, f_utf_string_length *written); #endif // _di_fl_utf_file_write_ /** @@ -187,7 +187,7 @@ extern "C" { * @see write() */ #ifndef _di_fl_utf_file_write_block_ - extern f_return_status fl_utf_file_write_block(const f_file file, const f_utf_string_dynamic buffer, f_utf_string_length *written); + extern f_return_status fl_utf_file_write_block(const f_file file, const f_utf_string_static buffer, f_utf_string_length *written); #endif // _di_fl_utf_file_write_block_ /** @@ -221,7 +221,7 @@ extern "C" { * @see write() */ #ifndef _di_fl_utf_file_write_until_ - extern f_return_status fl_utf_file_write_until(const f_file file, const f_utf_string_dynamic buffer, const f_utf_string_length total, f_utf_string_length *written); + extern f_return_status fl_utf_file_write_until(const f_file file, const f_utf_string_static buffer, const f_utf_string_length total, f_utf_string_length *written); #endif // _di_fl_utf_file_write_until_ /** @@ -255,7 +255,7 @@ extern "C" { * @see write() */ #ifndef _di_fl_utf_file_write_range_ - extern f_return_status fl_utf_file_write_range(const f_file file, const f_utf_string_dynamic buffer, const f_utf_string_range range, f_utf_string_length *written); + extern f_return_status fl_utf_file_write_range(const f_file file, const f_utf_string_static buffer, const f_utf_string_range range, f_utf_string_length *written); #endif // _di_fl_utf_file_write_range_ #ifdef __cplusplus -- 1.8.3.1