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
|
|
|
Goto Forum:
Current Time: Tue Jun 10 09:04:26 CEST 2025
Total time taken to generate the page: 0.04295 seconds
|