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

            Bug ID: 93672
           Summary: std::basic_istream::ignore hangs if delim MSB is set
           Product: gcc
           Version: 9.1.0
               URL: https://stackoverflow.com/questions/60140947/stdbasic-
                    istreamignore-hangs-if-delim-msb-is-set
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: erenon2 at gmail dot com
  Target Milestone: ---

The following program hangs:

#include <iostream>
#include <sstream>

int main()
{
  std::stringstream str;
  str.put('a');       // 1
  str.put('\x80');    // 2
  str.put('a');       // 3

  str.ignore(32, '\x80'); // hangs
  std::cout << str.tellg() << "\n";
}

Removing any of the numbered lines (1,2,3) makes the problem go away.
Using std::basic_stringstream<unsigned char> does not exhibit the issue.
Passing unsigned delim (that does not get sign extended) also fixes it.
ASAN or UBSAN is silent. `-D_GLIBCXX_DEBUG` does not make a difference.
GCC 5.4, 6.3, 8.2, 9.2 are affected.

Reply via email to