www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std.stream.Stream.copyFrom()

reply derick_eddington nospam.dot.yahoo.dot.com writes:
std.stream.Stream.copyFrom(Stream):

void copyFrom(Stream s)
{
//BUG  uint pos = position();    // not position of this
uint pos = s.position();     // save position of s
s.position(0);
copyFrom(s, s.size());
s.position(pos);
}


std.stream.Stream.copyFrom(Stream, uint):

void copyFrom(Stream s, uint count)
{
ubyte[] buf;
//BUG  buf.length = s.size();    // not size of s
buf.length = count;          // use specified size
s.readExact(buf, buf.length);
writeExact(buf, buf.length);
}
Mar 24 2005
next sibling parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
<derick_eddington nospam.dot.yahoo.dot.com> wrote in message 
news:d1vuka$1ed1$1 digitaldaemon.com...
 std.stream.Stream.copyFrom(Stream):

 void copyFrom(Stream s)
 {
 //BUG  uint pos = position();    // not position of this
 uint pos = s.position();     // save position of s
 s.position(0);
 copyFrom(s, s.size());
 s.position(pos);
 }


 std.stream.Stream.copyFrom(Stream, uint):

 void copyFrom(Stream s, uint count)
 {
 ubyte[] buf;
 //BUG  buf.length = s.size();    // not size of s
 buf.length = count;          // use specified size
 s.readExact(buf, buf.length);
 writeExact(buf, buf.length);
 }
wow. Those are bad bugs - I guess you're one of the first people to try to use copyFrom. I wonder if it ever worked or if those bugs crept in by accident somehow. Have you sent the fix to Walter? Just email him the fixed file. I would add a unittest, too, if you have time since I notice it isn't tested anywhere.
Mar 24 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message 
news:d200sa$1gvm$1 digitaldaemon.com...
 <derick_eddington nospam.dot.yahoo.dot.com> wrote in message 
 news:d1vuka$1ed1$1 digitaldaemon.com...
 std.stream.Stream.copyFrom(Stream):

 void copyFrom(Stream s)
 {
 //BUG  uint pos = position();    // not position of this
 uint pos = s.position();     // save position of s
 s.position(0);
 copyFrom(s, s.size());
 s.position(pos);
 }


 std.stream.Stream.copyFrom(Stream, uint):

 void copyFrom(Stream s, uint count)
 {
 ubyte[] buf;
 //BUG  buf.length = s.size();    // not size of s
 buf.length = count;          // use specified size
 s.readExact(buf, buf.length);
 writeExact(buf, buf.length);
 }
wow. Those are bad bugs - I guess you're one of the first people to try to use copyFrom. I wonder if it ever worked or if those bugs crept in by accident somehow. Have you sent the fix to Walter? Just email him the fixed file. I would add a unittest, too, if you have time since I notice it isn't tested anywhere.
actually there's another change to std.stream that I want to send to Walter so I'll just put your changes in with mine.
Mar 24 2005
parent derick_eddington nospam.dot.yahoo.dot.com writes:
Actually, I was just reading the source because I'm thinking of using Stream in
the future and saw it.  Thanks for sending the fix.


In article <d2016e$1hdj$1 digitaldaemon.com>, Ben Hinkle says...
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message 
news:d200sa$1gvm$1 digitaldaemon.com...
 <derick_eddington nospam.dot.yahoo.dot.com> wrote in message 
 news:d1vuka$1ed1$1 digitaldaemon.com...
 std.stream.Stream.copyFrom(Stream):

 void copyFrom(Stream s)
 {
 //BUG  uint pos = position();    // not position of this
 uint pos = s.position();     // save position of s
 s.position(0);
 copyFrom(s, s.size());
 s.position(pos);
 }


 std.stream.Stream.copyFrom(Stream, uint):

 void copyFrom(Stream s, uint count)
 {
 ubyte[] buf;
 //BUG  buf.length = s.size();    // not size of s
 buf.length = count;          // use specified size
 s.readExact(buf, buf.length);
 writeExact(buf, buf.length);
 }
wow. Those are bad bugs - I guess you're one of the first people to try to use copyFrom. I wonder if it ever worked or if those bugs crept in by accident somehow. Have you sent the fix to Walter? Just email him the fixed file. I would add a unittest, too, if you have time since I notice it isn't tested anywhere.
actually there's another change to std.stream that I want to send to Walter so I'll just put your changes in with mine.
Mar 25 2005
prev sibling parent Nick <Nick_member pathlink.com> writes:
In article <d1vuka$1ed1$1 digitaldaemon.com>,
derick_eddington nospam.dot.yahoo.dot.com says...
void copyFrom(Stream s, uint count)
{
  ubyte[] buf;
  //BUG  buf.length = s.size();    // not size of s
  buf.length = count;          // use specified size
  s.readExact(buf, buf.length);
  writeExact(buf, buf.length);
}
By the way, is it not a bit risky to assume the entire stream can fit in a memory buffer? And is it really appropriate to use uints for stream sizes? Why not use ulongs? Nick
Mar 27 2005