[libc-commits] [libc] [libc] Fix incorrect unsigned comparison (PR #135595)

Peng Liu via libc-commits libc-commits at lists.llvm.org
Mon Apr 14 09:50:06 PDT 2025


================
@@ -192,7 +192,7 @@ template <WriteMode write_mode> 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) {
----------------
winner245 wrote:

```suggestion
```
The outer `if` already guarantees that `buffered_digits - digits_to_write > 0` is true. So the underflow does not exist here. However, this `if` is truly redundant. 

https://github.com/llvm/llvm-project/pull/135595


More information about the libc-commits mailing list