[LLVMbugs] [Bug 13113] New: std::streambuf calls underflow too early.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jun 14 11:51:26 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13113

             Bug #: 13113
           Summary: std::streambuf calls underflow too early.
           Product: libc++
           Version: unspecified
          Platform: PC
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: hi at mokafolio.de
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


std::streambuf calls underflow already when the requested bytes are equal to
the available bytes in the get area. The following example calls underflow
twice while I'd expect it to only be called once:

#include <iostream>
#include <vector>
#include <sstream>

class TestStringBuf : 
public std::stringbuf
{
public:

    int_type underflow()
    {
        std::cout<<"TestStringBuf underflow"<<std::endl;
        return std::stringbuf::underflow();
    }
};

int main(int argc, const char * argv[])
{
    TestStringBuf buf;
    std::iostream stream(&buf);

    stream << "tesr";

    std::vector<char> data(4);
    stream.read(&data[0], 4);

    for(int i=0; i<data.size(); ++i)
        std::cout<<data[i];
    std::cout<<std::endl;

    return 0;
}

This happens also with classes that inherit from streambuf directly. This might
not seem bad for default implementations where EOF is returned, but if you
receive new data on a blocking socket for instance, this could potentially
block (infinetely) for no apparent reason.

thank you.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list