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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.2.0
    • 27. Input/Output
    • None
    • All

    • Patch Available
    • 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

            farid Farid Zaripov
            farid Farid Zaripov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: