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 libstdc++/106248] [11/12/13 Regression] operator>>std::basic_istream at boundary condition behave differently in different opt levels
Date: Mon, 11 Jul 2022 11:20:07 +0000	[thread overview]
Message-ID: <bug-106248-4-Rc5PfyBn52@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106248-4@http.gcc.gnu.org/bugzilla/>

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-07-11
             Status|UNCONFIRMED                 |NEW
            Summary|operator>>std::basic_istrea |[11/12/13 Regression]
                   |m at boundary condition     |operator>>std::basic_istrea
                   |behave differently in       |m at boundary condition
                   |different opt levels        |behave differently in
                   |                            |different opt levels
      Known to fail|                            |11.1.0
     Ever confirmed|0                           |1
      Known to work|                            |10.4.0

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
In C++20 mode the operator>> overload has changed to one that binds to char
(&)[10] and so knows the size of the output buffer. The loop stops reading when
it has written as many chars as will fit in the buffer, and does not set
eofbit:

              if (__extracted < __num - 1
                  && __traits_type::eq_int_type(__c, __eof))
                __err |= ios_base::eofbit;

In pre-C++20 modes, operator>> just binds to a const char* and will overflow it
if the buffer is not big enough. However, libstdc++ now uses
__builtin_object_size to detect the size of the buffer, and so will stop
writing when the buffer is full. That detection using __builtin_object_size
only works when optimization is enabled, which is why we stop before setting
the eofbit when optimizing.

I don't want to just remove the size detection, because it prevents undefined
behaviour. But we need a way to prevent overflow without altering the
observable behaviour for C++17 and earlier.

  parent reply	other threads:[~2022-07-11 11:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11  1:39 [Bug libstdc++/106248] New: " Ting.Wang.SH at ibm dot com
2022-07-11  6:11 ` [Bug libstdc++/106248] " pinskia at gcc dot gnu.org
2022-07-11 11:07 ` redi at gcc dot gnu.org
2022-07-11 11:20 ` redi at gcc dot gnu.org [this message]
2022-07-11 11:34 ` [Bug libstdc++/106248] [11/12/13 Regression] " redi at gcc dot gnu.org
2022-07-11 11:36 ` redi at gcc dot gnu.org
2022-07-11 11:46 ` redi at gcc dot gnu.org
2022-07-11 12:38 ` redi at gcc dot gnu.org
2022-07-11 13:32 ` redi at gcc dot gnu.org
2022-07-12 22:40 ` cvs-commit at gcc dot gnu.org
2022-07-12 22:41 ` [Bug libstdc++/106248] [11/12 " redi at gcc dot gnu.org
2022-07-25 15:05 ` rguenth at gcc dot gnu.org
2022-08-03 13:47 ` cvs-commit at gcc dot gnu.org
2022-08-03 13:48 ` [Bug libstdc++/106248] [11 " redi at gcc dot gnu.org
2022-09-07 17:49 ` cvs-commit at gcc dot gnu.org
2022-09-07 17:53 ` redi 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-106248-4-Rc5PfyBn52@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).