Home » U++ Library support » U++ Core » Bug in Core/Stream.cpp
Bug in Core/Stream.cpp [message #39946] |
Wed, 15 May 2013 11:55 |
|
Hi,
Upp source from SVN rev. 6071
We where trying to use a Md5Stream object and found it gave different results with these two examples, both are reading a small text file and calculating the Md5 hash:
Wrong result:
FileIn f_in( aFileName );
Md5Stream md5;
md5.Put( f_in );
mMD5_Hash = md5.FinishString();
Correct result:
String fdata_1 = LoadFile( aFileName ) ;
Md5Stream md5_s ;
md5_s.Put( fdata_1 ) ;
String md5_hash1 = md5_s.FinishString();
The error is in the Put function in Stream.cpp line 458:
Put(buffer.operator const byte *(), click);
The second parameter "click" is the buffer size, not the size of contents in the buffer. It should be "n", so the corrected function end up like this:
void Stream::Put(Stream& s, int64 size, dword click) {
Buffer<byte> buffer(click);
while(size) {
dword n = s.Get(buffer, (int)min<int64>(click, size));
if(n == 0)
break;
Put(buffer.operator const byte *(), n);
size -= n;
}
}
Regards,
Steffen
|
|
|
Re: Bug in Core/Stream.cpp [message #39955 is a reply to message #39946] |
Thu, 16 May 2013 10:46 |
|
Hi again,
Here is another example showing the same error in a simple file copy situation.
FileIn in(GetDataFile("TestFile.txt"));
FileOut out(GetDataFile("Copy Of TestFile.txt"));
out.Put(in);
out.Flush();
LOG("Original filesize: " << in.GetSize());
LOG("Size of Copy: " << out.GetSize());
Log output:
Original filesize: 128
Size of Copy: 4096
It works if I exchange the second parameter click with n in Stream.cpp:458
Regards,
Steffen
|
|
|
|
Goto Forum:
Current Time: Thu Apr 25 15:15:53 CEST 2024
Total time taken to generate the page: 0.02588 seconds
|