When compiled with gcc 4.3.1 the program below fails with SIGSEGV:

$ cat z.cpp && g++ z.cpp && ./a.out
#include <cassert>
#include <istream>
#include <streambuf>

int main ()
{
    static int x = '0';

    struct: std::streambuf {
        // unbuffered, always successfully reads one character
        int_type underflow () { return x++; }
    } sb;

    // "endless" stream that never reaches EOF
    std::istream endless (&sb);

    char s [4] = "";

    endless.read (s, sizeof s);

    // expect to extract as many characters as requested
    assert (endless.good ());
    assert (sizeof s == endless.gcount ());
    assert ('0' == s [0] && '1' == s [1] && '2' == s [2] && '3' == s [3]);
}
Segmentation fault


-- 
           Summary: SIGSEGV on istream::read() in unbuffered mode
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38476

Reply via email to