https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114325

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Indeed. Here's the fix:

--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -4124,14 +4124,14 @@ namespace __format
                    __uval = make_unsigned_t<_Tp>(~__arg) + 1u;
                  else
                    __uval = __arg;
-                 const auto __n = __detail::__to_chars_len(__uval) + __neg;
-                 if (auto __res = __sink_out._M_reserve(__n))
+                 const auto __n = __detail::__to_chars_len(__uval);
+                 if (auto __res = __sink_out._M_reserve(__n + __neg))
                    {
                      auto __ptr = __res.get();
                      *__ptr = '-';
                      __detail::__to_chars_10_impl(__ptr + (int)__neg, __n,
                                                   __uval);
-                     __res._M_bump(__n);
+                     __res._M_bump(__n + __neg);
                      __done = true;
                    }
                }

Reply via email to