public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/110239] [14 regression] std/format/functions/format.cc fails after r14-1648-g628ba410b9265d
Date: Mon, 26 Jun 2023 13:36:02 +0000	[thread overview]
Message-ID: <bug-110239-4-zAXdhydkEW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110239-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> ==55393==ERROR: AddressSanitizer: global-buffer-overflow on address
> 0x0000004c9324 at pc 0x000000432970 bp 0x7ffe2c7fcf80 sp 0x7ffe2c7fcf78
> READ of size 4 at 0x0000004c9324 thread T0
>     #0 0x43296f in std::pair<unsigned short, wchar_t const*>
> std::__format::__parse_integer<wchar_t>(wchar_t const*, wchar_t const*)
> /home/jwakely/gcc/14/include/c++/14.0.0/format:301

That's actually a separate bug that only affects formatting wide strings. I
have a fix for that, but the bug for 32-bit targets is simply:

@@ -2118,7 +2105,7 @@ namespace __format
        typename basic_format_context<_Out, _CharT>::iterator
        format(const void* __v, basic_format_context<_Out, _CharT>& __fc) const
        {
-         auto __u = reinterpret_cast<__UINT64_TYPE__>(__v);
+         auto __u = reinterpret_cast<__UINTPTR_TYPE__>(__v);
          char __buf[2 + sizeof(__v) * 2];
          auto [__ptr, __ec] = std::to_chars(__buf + 2, std::end(__buf),
                                             __u, 16);

Casting the pointer to uint64_t sign extends it, which produces a very large
64-bit integer that doesn't fit in __buf.

  parent reply	other threads:[~2023-06-26 13:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 15:27 [Bug other/110239] New: " seurer at gcc dot gnu.org
2023-06-14  4:29 ` [Bug other/110239] " redi at gcc dot gnu.org
2023-06-23 18:36 ` redi at gcc dot gnu.org
2023-06-26 13:36 ` redi at gcc dot gnu.org [this message]
2023-06-26 16:43 ` [Bug libstdc++/110239] " cvs-commit at gcc dot gnu.org
2023-06-26 16:45 ` redi at gcc dot gnu.org
2023-06-29 23:01 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110239-4-zAXdhydkEW@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).