From 806f26ba23c823233bc782c4c588c11968cdebc8 Mon Sep 17 00:00:00 2001 From: "Wu, Yingcong" Date: Mon, 14 Apr 2025 15:36:04 +0800 Subject: [PATCH 1/3] fix --- libc/src/stdio/printf_core/float_dec_converter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/src/stdio/printf_core/float_dec_converter.h b/libc/src/stdio/printf_core/float_dec_converter.h index ee5549825a6f2..178f228527f68 100644 --- a/libc/src/stdio/printf_core/float_dec_converter.h +++ b/libc/src/stdio/printf_core/float_dec_converter.h @@ -192,7 +192,7 @@ template class FloatWriter { RET_IF_RESULT_NEGATIVE(writer->write({block_buffer, digits_to_write})); } RET_IF_RESULT_NEGATIVE(writer->write(DECIMAL_POINT)); - if (buffered_digits - digits_to_write > 0) { + if (buffered_digits > digits_to_write) { // Write the digits after the decimal point. RET_IF_RESULT_NEGATIVE( writer->write({block_buffer + digits_to_write, @@ -222,7 +222,7 @@ template class FloatWriter { RET_IF_RESULT_NEGATIVE(writer->write(MAX_BLOCK_DIGIT, digits_to_write)); } RET_IF_RESULT_NEGATIVE(writer->write(DECIMAL_POINT)); - if ((BLOCK_SIZE * max_block_count) - digits_to_write > 0) { + if ((BLOCK_SIZE * max_block_count) > digits_to_write) { RET_IF_RESULT_NEGATIVE(writer->write( MAX_BLOCK_DIGIT, (BLOCK_SIZE * max_block_count) - digits_to_write)); } From 1c6c1b576a334752977cac2bee4ab13af1788e3d Mon Sep 17 00:00:00 2001 From: "Wu, Yingcong" Date: Tue, 15 Apr 2025 13:10:28 +0800 Subject: [PATCH 2/3] remove redundent if --- libc/src/stdio/printf_core/float_dec_converter.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libc/src/stdio/printf_core/float_dec_converter.h b/libc/src/stdio/printf_core/float_dec_converter.h index 178f228527f68..ed004f9a26a13 100644 --- a/libc/src/stdio/printf_core/float_dec_converter.h +++ b/libc/src/stdio/printf_core/float_dec_converter.h @@ -186,11 +186,10 @@ template class FloatWriter { if (total_digits_written < digits_before_decimal && total_digits_written + buffered_digits >= digits_before_decimal && has_decimal_point) { + // digits_to_write > 0 guaranteed by outer if size_t digits_to_write = digits_before_decimal - total_digits_written; - if (digits_to_write > 0) { - // Write the digits before the decimal point. - RET_IF_RESULT_NEGATIVE(writer->write({block_buffer, digits_to_write})); - } + // Write the digits before the decimal point. + RET_IF_RESULT_NEGATIVE(writer->write({block_buffer, digits_to_write})); RET_IF_RESULT_NEGATIVE(writer->write(DECIMAL_POINT)); if (buffered_digits > digits_to_write) { // Write the digits after the decimal point. @@ -217,10 +216,9 @@ template class FloatWriter { total_digits_written + BLOCK_SIZE * max_block_count >= digits_before_decimal && has_decimal_point) { + // digits_to_write > 0 guaranteed by outer if size_t digits_to_write = digits_before_decimal - total_digits_written; - if (digits_to_write > 0) { - RET_IF_RESULT_NEGATIVE(writer->write(MAX_BLOCK_DIGIT, digits_to_write)); - } + RET_IF_RESULT_NEGATIVE(writer->write(MAX_BLOCK_DIGIT, digits_to_write)); RET_IF_RESULT_NEGATIVE(writer->write(DECIMAL_POINT)); if ((BLOCK_SIZE * max_block_count) > digits_to_write) { RET_IF_RESULT_NEGATIVE(writer->write( From 38b5517f32cbe23203b4978edb414363c65db1f8 Mon Sep 17 00:00:00 2001 From: "Wu, Yingcong" Date: Tue, 15 Apr 2025 18:29:45 -0700 Subject: [PATCH 3/3] trigger CI