[libc-commits] [libc] [libc] Add support for writing to wchar_t in printf_core/ converter functions. (PR #230246)

Simon Tatham via libc-commits libc-commits at lists.llvm.org
Fri Oct 16 04:52:15 PDT 2026


================
@@ -127,20 +132,21 @@ LIBC_INLINE int estimate_log10(int exponent_of_2) {
 // `decimal_digits` has a place value of _at least_ 10^-precision. But also, at
 // most `MAX_DIGITS` digits are returned, so the caller may need to pad it at
 // the end with the appropriate number of extra 0s.
-LIBC_INLINE
-DigitsOutput decimal_digits(DigitsInput input, int precision, bool e_mode) {
+template <typename CharT>
+LIBC_INLINE DigitsOutput<CharT> decimal_digits(DigitsInput input, int precision,
+                                               bool e_mode) {
   if (input.mantissa == 0) {
-    // Special-case zero, by manually generating the right number of zero
-    // digits and setting an appropriate exponent.
-    DigitsOutput output;
+    // Special-case zero, by manually setting the right number of zero digits
+    // and setting an appropriate exponent.
+    DigitsOutput<CharT> output = {};
     if (!e_mode) {
       // In F mode, it's enough to return an empty string of digits. That's the
       // same thing we do when given a nonzero number that rounds down to 0.
       output.ndigits = 0;
       output.exponent = -precision - 1;
     } else {
-      // In E mode, generate a string containing the expected number of 0s.
-      __builtin_memset(output.digits, '0', precision);
----------------
statham-arm wrote:

Hi @strel-12 , the removal of this memset has introduced a bug. `output.digits` was previously being set to all zeroes in the sense of the ASCII character `'0'`, and now it's being set to all NUL bytes!

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


More information about the libc-commits mailing list