Article View: gnu.g++.lib.bug
Article #120Bug in istream::get
From: David.Detlefs
Date: Sat, 05 Aug 1989 18:56
Date: Sat, 05 Aug 1989 18:56
47 lines
1617 bytes
1617 bytes
I am using G++ 1.35 and libg++ 1.35.1.
Consider the following program:
--------------------------------------------------
#include <stream.h>
void main() {
filebuf fin;
fin.open("bug4-input", input);
istream ist(&fin);
char s[100];
for (int i = 0; i < 50; i++) s[i] = '#';
ist.get(s, 3);
cout << "S is " << s << ".\n";
}
--------------------------------------------------
where 'bug4-input' is the file:
--------------------------------------------------
123456789
--------------------------------------------------
When compiled with G++ and libg++, this program prints
S is 1234.
Note that AT&T cfront (1.2.1 and a beta test of 2.0) do *not* print
what you might expect, which is
S is 123.
Instead, they print
S is 12.
An argument can be made that this is correct behavior, since
Stroustrup p. 237 says "... istream::get reads at most n characters
into a character vector starting at p [equivalent to s in this
program]." Since get inserts the terminating null character in
addition to the characters read, "12\0" are the correct three
characters that should be put in s.
I am in the process of compiling and testing a fix, which I will post
if it works.
Dave
Technical Details
Message-ID:
<8908051856.AA21241@AENEAS.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!F.GP.CS.CMU.EDU!David.DetlefsShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!F.GP.CS.CMU.EDU!David.Detlefs From: David.Detlefs@F.GP.CS.CMU.EDU Newsgroups: gnu.g++.lib.bug Subject: Bug in istream::get Message-ID: <8908051856.AA21241@AENEAS.MIT.EDU> Date: 5 Aug 89 18:56:13 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 47