This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/81395] [5/6/7/8 Regression] basic_filebuf::overflow recurses and overflows stack


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

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think uncommitted mode is correct there, because stdio requires a seek
on the underlying FILE before writing to it. Setting _M_reading ensures that
will happen before the next write. Uncommitted mode would cause that seek to be
skipped.

So maybe this workaround (from comment 1) is a reasonable solution:

@@ -920,7 +925,7 @@
     {
       // Part one: update the output sequence.
       bool __testvalid = true;
-      if (this->pbase() < this->pptr())
+      if (this->pbase() < this->pptr() && __builtin_expect(!_M_reading, 1))
        {
          const int_type __tmp = this->overflow();
          if (traits_type::eq_int_type(__tmp, traits_type::eof()))

This just prevents the infinite recursion, by not trying to perform a pending
write if we're currently in read mode.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]