Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-576

std::basic_streambuf<>::xsputn() incorrectly inserts the data, that is the part of the internal buffer

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.2.0
    • Component/s: 27. Input/Output
    • Labels:
      None
    • Environment:

      All

    • Patch Info:
      Patch Available
    • Severity:
      Incorrect Behavior

      Description

      The test below aborts on assert.

      test.cpp:
      ------------------
      #include <sstream> // for stringbuf
      #include <string> // for string
      #include <cassert> // for assert()

      struct PubBuf: std::stringbuf
      {
      char* Pbase () const

      { return this->pbase (); }

      };

      int main ()
      {
      // 512 is the default buffer size of the basic_stringbuf
      std::string s (512, 'a');

      std::stringbuf sbuf (s);
      PubBuf& buf = (PubBuf&)sbuf;

      std::streamsize res = buf.sputn (buf.Pbase (), 128);
      s.append (s.begin (), s.begin () + 128);

      const std::string& str = buf.str ();

      assert (res == 128);
      assert (str.size () == s.size ());
      assert (str == s);

      return 0;
      }
      ------------------

      The test output:
      ------------------
      test: test.cpp:25: int main (): Assertion `str == s' failed.
      Aborted
      ------------------

        Attachments

        1. 27.stringbuf.xsputn.stdcxx-576.cpp
          2 kB
          Farid Zaripov
        2. sstream.cc.diff
          1 kB
          Farid Zaripov

          Activity

            People

            • Assignee:
              farid Farid Zaripov
              Reporter:
              farid Farid Zaripov

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment