This is the mail archive of the libstdc++-prs@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libstdc++/92: Bug in istream::get(basic_streambuf*);



>Number:         92
>Category:       libstdc++
>Synopsis:       Bug in istream::get(basic_streambuf*);
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 28 10:27:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     bgarcia@laurelnetworks.com
>Release:        unknown-1.0
>Organization:
>Environment:
linux x86, libstdc++ v.2.90.8, gcc v 2.95.2
>Description:
The function istream::get(basic_streambuf*) appears
to screw up on some 8k buffer boundary.  It will return
WITHOUT having hit the delimiter, and it will drop a
character in the process.
>How-To-Repeat:
First, create a file called "conf" with at least 1500
lines of "1234567890".

Next, compile and run the following program:

#include <fstream>
#include <iostream>
#include <sstream>

int main(int argc, char** argv)
{
    std::ifstream infile;
    infile.open("conf");
    if (!infile.is_open())
    {
        std::cout << "Couldn't open conf file" << std::endl;
        return 1;
    }

    unsigned numbytes(0);
    unsigned numlines(0);

    while (!infile.eof())
    {
        while (infile.peek() == '\n')
        {
            infile.get();
            ++numbytes;
            ++numlines;
        }

        std::string line;

        {
            std::ostringstream line_ss;
            infile.get(*(line_ss.rdbuf()));
            line = line_ss.str();
            numbytes += line.size();
        }

        if (line != "1234567890")
        {
            std::cout << "Line " << numlines << ", byte " << numbytes
                      << ", got: \"" << line << "\"" << std::endl;
        }

    }
    return 0;
}

You will get output similar to:

Line 745, byte 8192, got: "1234567"
Line 745, byte 8194, got: "90"
Line 1491, byte 16383, got: "123"
Line 1491, byte 16389, got: "567890"
Line 2982, byte 32766, got: "123456"
Line 2982, byte 32769, got: "890"
Line 3728, byte 40957, got: "12"
Line 3728, byte 40964, got: "4567890"
Line 4473, byte 49148, got: "123456789"
Line 5219, byte 57339, got: "12345"
Line 5219, byte 57343, got: "7890"
Line 6710, byte 73722, got: "12345678"
Line 6710, byte 73723, got: "0"
Line 7456, byte 81913, got: "1234"
Line 7456, byte 81918, got: "67890"
Line 8652, byte 95044, got: ""

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]