public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/93672] [11/12/13 Regression] std::basic_istream::ignore hangs if delim MSB is set Date: Thu, 02 May 2024 14:16:20 +0000 [thread overview] Message-ID: <bug-93672-4-PDdnxXjOMV@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-93672-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93672 --- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-13 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:fcf60d0baafa1245f768ac375dc60a07e92e9673 commit r13-8675-gfcf60d0baafa1245f768ac375dc60a07e92e9673 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Apr 4 10:33:33 2024 +0100 libstdc++: Fix infinite loop in std::istream::ignore(n, delim) [PR93672] A negative delim value passed to std::istream::ignore can never match any character in the stream, because the comparison is done using traits_type::eq_int_type(sb->sgetc(), delim) and sgetc() never returns negative values (except at EOF). The optimized version of ignore for the std::istream specialization uses traits_type::find to locate the delim character in the streambuf, which _can_ match a negative delim on platforms where char is signed, but then we do another comparison using eq_int_type which fails. The code then keeps looping forever, with traits_type::find locating the character and traits_type::eq_int_type saying it's not a match, so traits_type::find is used again and finds the same character again. A possible fix would be to check with eq_int_type after a successful find, to see whether we really have a match. However, that would be suboptimal since we know that a negative delimiter will never match using eq_int_type. So a better fix is to adjust the check at the top of the function that handles delim==eof(), so that we treat all negative delim values as equivalent to EOF. That way we don't bother using find to search for something that will never match with eq_int_type. The version of ignore in the primary template doesn't need a change, because it doesn't use traits_type::find, instead characters are extracted one-by-one and always matched using eq_int_type. That avoids the inconsistency between find and eq_int_type. The specialization for std::wistream does use traits_type::find, but traits_type::to_int_type is equivalent to an implicit conversion from wchar_t to wint_t, so passing a wchar_t directly to ignore without using to_int_type works. libstdc++-v3/ChangeLog: PR libstdc++/93672 * src/c++98/istream.cc (istream::ignore(streamsize, int_type)): Treat all negative delimiter values as eof(). * testsuite/27_io/basic_istream/ignore/char/93672.cc: New test. * testsuite/27_io/basic_istream/ignore/wchar_t/93672.cc: New test. (cherry picked from commit 2d694414ada8e3b58f504c1b175d31088529632e)
next prev parent reply other threads:[~2024-05-02 14:16 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-93672-4@http.gcc.gnu.org/bugzilla/> 2024-04-03 17:18 ` [Bug libstdc++/93672] " redi at gcc dot gnu.org 2024-04-03 17:41 ` redi at gcc dot gnu.org 2024-04-03 19:40 ` redi at gcc dot gnu.org 2024-04-04 9:53 ` [Bug libstdc++/93672] [11/12/13/14 Regression] " redi at gcc dot gnu.org 2024-04-15 18:29 ` cvs-commit at gcc dot gnu.org 2024-04-15 18:32 ` [Bug libstdc++/93672] [11/12/13 " redi at gcc dot gnu.org 2024-05-02 14:16 ` cvs-commit at gcc dot gnu.org [this message] 2024-05-02 14:17 ` [Bug libstdc++/93672] [11/12 " redi at gcc dot gnu.org 2024-06-12 11:21 ` rguenth 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-93672-4-PDdnxXjOMV@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: linkBe 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).