Serious BUG in fstream 
Author Message
 Serious BUG in fstream

Greets,

    Do not that there is no default open mode when using an fstream.  Try
using ios::binary|ios::in before the read.  :)

Regards,

Joe

Quote:

> If there is a byte of value 26 (ctrl-Z) inside a file subject to input,
> fstream "thinks" that this is end of file. You cannot read any value
> beyond a byte of 26.

> Below is the sample code I use for this:

> fstream fio("myfile.dat", ios::binary);
> fio.read((char *) &mystruct, sizeof(mystruct));

> Any workaround?

> Sent via Deja.com http://www.*-*-*.com/
> Before you buy.



Tue, 25 Feb 2003 01:49:37 GMT  
 Serious BUG in fstream
No, this is not the case, I just forgot to put it in the post.

Bug remains...



Quote:

> Greets,

>     Do not that there is no default open mode when using an fstream.
Try
> using ios::binary|ios::in before the read.  :)

> Regards,

> Joe




Quote:
> > If there is a byte of value 26 (ctrl-Z) inside a file subject to
input,
> > fstream "thinks" that this is end of file. You cannot read any value
> > beyond a byte of 26.

> > Below is the sample code I use for this:

> > fstream fio("myfile.dat", ios::binary);
> > fio.read((char *) &mystruct, sizeof(mystruct));

> > Any workaround?

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 26 Feb 2003 15:13:47 GMT  
 Serious BUG in fstream

Quote:
> No, this is not the case, I just forgot to put it in the post.

> Bug remains...

No, it does not.  Please study the appended program
carefully, keeping in mind Joe's suggestion about
using ios::in, and decide whether the output of
  26 1 2
does not contradict your assertion of a bug with
respect to treatment of \x1A on binary streams.
This result is produced by VC6, SP4.

Quote:


> > Greets,

> >     Do not that there is no default open mode when using an fstream.
> Try
> > using ios::binary|ios::in before the read.  :)

> > Regards,

> > Joe



> > > If there is a byte of value 26 (ctrl-Z) inside a file subject to
> input,
> > > fstream "thinks" that this is end of file. You cannot read any value
> > > beyond a byte of 26.

> > > Below is the sample code I use for this:

> > > fstream fio("myfile.dat", ios::binary);
> > > fio.read((char *) &mystruct, sizeof(mystruct));

> > > Any workaround?

Yes, as Joe stated.  To wit:

#include <fstream>
#include <iostream>

int main()
{
  struct DooDad {
    int a;
    int b;
    int c;
  } ddOut = { 26, 1, 2}, ddIn;

  {
    std::fstream fio("myfile.dat", std::ios::binary|std::ios::out );
    fio.write( reinterpret_cast<const char *>(&ddOut), sizeof ddOut );
  }
  {
    std::fstream fio("myfile.dat", std::ios::binary|std::ios::in );
    fio.read(reinterpret_cast<char *>(&ddIn), sizeof ddIn);
    std::cout << ddIn.a << ' ' << ddIn.b << ' ' << ddIn.c << '\n';
  }

Quote:
}

--
Larry Brasfield
Above opinions may be mine alone.



Thu, 27 Feb 2003 04:44:37 GMT  
 Serious BUG in fstream
One thing to remember which used to get me before I truly grokked
iostreams:

Opening a stream in binary doesn't prevent interpretation by the
various formatting extractors.  If you use operator >> you'll still
get all sorts of interpretation of the input data.

All that opening a stream in binary does for you is suppress
system-specific conversions.  This usually means only that C newlines
\n will not be converted to CR-LF sequences \r\n.

If you want to avoid all interpretation of the data, you need to use
the unformatted input functions such as read()

Joe O'


Quote:
> Sorry for the e{*filter*}d false alarm :-x

> I could not reproduce the bug, perhaps ios::binary option was
missing.

> Sent via Deja.com http://www.*-*-*.com/
> Before you buy.



Sun, 02 Mar 2003 03:00:00 GMT  
 Serious BUG in fstream
Sorry for the e{*filter*}d false alarm :-x

I could not reproduce the bug, perhaps ios::binary option was missing.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 02 Mar 2003 22:20:50 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. bug in fstream? (works with fstream.h)

2. Serious math optimzer bug

3. Serious Optimizer Bug in VC4.0/4.2

4. Serious bug in ATL

5. Serious bug in VC++ 6.0!

6. SERIOUS BUG in VC6.00

7. Serious bug in MSVC runtime library

8. Serious time/date bug in Visual C++

9. Serious VC 5 Bug -- Simple to Repro

10. Serious Optimizer Bug in VC4.0/4.2

11. declaring functions (was Re: serious cube root library bug)

12. Serious BUG in CFileDialog Class

 

 
Powered by phpBB® Forum Software