<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - raw_svector_ostream::pwrite problems"
   href="https://llvm.org/bugs/show_bug.cgi?id=23266">23266</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>raw_svector_ostream::pwrite problems
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yaron.keren@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, rafael.espindola@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi Rafael, 

Try adding this to the raw_pwrite_stream_test.cpp unit test, which will fail.

  SmallString<16> Buffer4;
  raw_svector_ostream OS4(Buffer4);
  OS4.pwrite(Test.data(), Test.size(), 0);
  OS4 << '4';
  StringRef S4 = OS4.str();
  EXPECT_EQ(S4, "4est");

While raw_fd_ostream::pwrite is careful to keep the current position so you can
do random r/w without disturbing the current stream position,
raw_svector_ostream::pwrite does not keep it, assuming the currrent position is
the vector size. Thus any write after pwrite will always occur at the end of
the vector and following the previous write(), inconsistent with
raw_svector_ostream::pwrite and programmer expectation.

Furthermore, the code

  if (End > OS.size())
    OS.resize(End);

must call resync() as it may modify the OS vector without updating the pointers
OutBufStart, OutBufEnd and OutBufCur.

These problems cause sometime corrupt ELF object file when written into a
raw_svector_ostream instead of raw_fd_ostream.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>