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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<r...@gcc.gnu.org>:

https://gcc.gnu.org/g:2d40cd2f199e32f185d4b72db2043e91313ab7f2

commit r13-7511-g2d40cd2f199e32f185d4b72db2043e91313ab7f2
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Mon Jun 26 14:46:46 2023 +0100

    libstdc++: Fix std::format for pointers [PR110239]

    The formatter for pointers was casting to uint64_t which sign extends a
    32-bit pointer and produces a value that won't fit in the provided
    buffer. Cast to uintptr_t instead.

    There was also a bug in the __parse_integer helper when converting a
    wide string to a narrow string in order to use std::from_chars on it.
    The function would always try to read 32 characters, even if the format
    string was shorter than that. Fix that bug, and remove the constexpr
    implementation of __parse_integer by just using __from_chars_alnum
    instead of from_chars, because that's usable in constexpr even in
    C++20.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110239
            * include/std/format (__format::__parse_integer): Fix buffer
            overflow for wide chars.
            (formatter<const void*, C>::format): Cast to uintptr_t instead
            of uint64_t.
            * testsuite/std/format/string.cc: Test too-large widths.

    (cherry picked from commit 3bb9f9329c378934541ae4cff9977b7487e97cf0)

Reply via email to