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]

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


The following reply was made to PR libstdc++/92; it has been noted by GNATS.

From: brent@rcfile.org
To: bgarcia@laurelnetworks.com
Cc: libstdc++-gnats@sourceware.cygnus.com
Subject: Re: libstdc++/92: Bug in istream::get(basic_streambuf*);
Date: Mon, 2 Oct 2000 01:20:11 -0400

 On 28 Sep 2000 at 17:23 (-0000), bgarcia@laurelnetworks.com wrote:
 | >Environment:
 | linux x86, libstdc++ v.2.90.8, gcc v 2.95.2
 
 verified that most recent cvs has this bug as well. thanks for the bug 
 report. I'll provide a patch for this tomorrow.
 
 cheers,
   brent
 
 | >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:
 
 -- 
 All opinions expressed are My own, unless otherwise attributed. In
 presenting facts, I expressly reserve the right to be Wrong. Portions
 of this message authored by Me are subject to the Free Thought License.

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