From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 848803846420; Wed, 3 Apr 2024 17:41:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 848803846420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712166105; bh=4VFlo9aPk8gW8Ydx4DAR6MU/0oLuFOrEV9SJdY6HeGs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IUFv+JyWfSi2FI2KjM0GO9ahOQkEBOtFTMaldLUzYqaceF8dhLFDDHsdgVZz1Qz2e 2uCtx6Zb1vTqMRhjxQoKROEzYb4W0mgIxxweV1vE0MNPjY5TSjd5XyCuR5+FCxu0IV zqt8396s2g1y8fdoCMNiji2PYT3x3vz0T7Ho3aCc= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/93672] std::basic_istream::ignore hangs if delim MSB is set Date: Wed, 03 Apr 2024 17:41:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 9.1.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D93672 --- Comment #2 from Jonathan Wakely --- On second thoughts, I don't think that fix is right. istream::ignore takes an int_type for the delimiter, so passing it a char_t= ype with a negative value will confuse it. For example, str.ignore(n, '\xff`) w= ill treat the delimiter as EOF and ignore up to n chars, ignoring any '\xff` characters that might be in the stream buffer's get area. That means it's w= rong to call ignore(n, '\xff') on a platform where char is signed, because it wo= n't do what you expect (unless you're really intending to treat \xff as EOF). This case is similar, it ignores up to n characters, or until sgetc() retur= ns a character equal to '\x80' ... but that can never happen because sgetc() nev= er returns a negative value unless it reaches EOF. So there is a gcc bug here, because we should not loop forever. But the pro= blem is that we use inconsistent conditions for deciding whether we've found the delimiter.=