<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 --- - istream::readsome() does not construct sentry"
   href="https://llvm.org/bugs/show_bug.cgi?id=28217">28217</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>istream::readsome() does not construct sentry
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.5
          </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>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>lavr@ncbi.nlm.nih.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Since LLVM implementation of istream::readsome() does not seem to construct the
sentry object (which is required in C++11 and which was also implicitly
required by an older standard), reading past EOF may cause applications to
enter endless loops.

Consider the following scenario: code reads a stream with readsome() in a
do..while(stream) loop.   At the EOF in_avail() returns -1, which makes
readsome()  assert an eofbit.  operator bool returns true on such a stream,
restarting the loop.  Since sentry is not constructed, no additional bits are
set in the stream state when readsome() is re-entered, this process continues
indefinitely.

Had sentry been constructed, the failbit would have been set, breaking the
loop.

Alternatively, the older revision of the standard explicitly noted that if
stream wasn't good(), readsome() must set failbit on such a stream (this was in
addition to the implicit rule for all unformatted input functions to construct
sentry first before proceeding with the input).

basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
{
    __gc_ = 0;
    streamsize __c = this->rdbuf()->in_avail();
    switch (__c)
    {
    case -1:
        this->setstate(ios_base::eofbit);
        break;
    case 0:
        break;
    default:
        read(__s, _VSTD::min(__c, __n));
        break;
    }
    return __gc_;
}</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>