Skip to content

Commit

Permalink
Fix files with preload data sometimes not working
Browse files Browse the repository at this point in the history
  • Loading branch information
SCell555 committed Jan 21, 2022
1 parent aabfc1e commit cde87a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion Handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#define INITGUID
#include "Alloc.h"
#include "ComTry.h"
Expand Down
18 changes: 11 additions & 7 deletions LimitedStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,31 @@ STDMETHODIMP CLimitedCachedInStream::Read(void *data, UInt32 size, UInt32 *proce
UInt64 newPos = _startOffset + _virtPos;
UInt64 offsetInCache = newPos - _cachePhyPos;
HRESULT res = S_OK;
UInt32 tmpSize = 0;
if (newPos >= _cachePhyPos &&
offsetInCache <= _cacheSize &&
size <= _cacheSize - (size_t)offsetInCache)
offsetInCache <= _cacheSize)
{
if (size != 0)
memcpy(data, _cache + (size_t)offsetInCache, size);
{
memcpy(data, _cache + (size_t)offsetInCache, min(size, _cacheSize - (size_t)offsetInCache));
tmpSize = (UInt32)min(_cacheSize - (size_t)offsetInCache, size);
size -= tmpSize;
}
}
else
if (size != 0)
{
newPos += _physOffset;
if (newPos != _physPos)
{
_physPos = newPos;
RINOK(SeekToPhys());
}
res = _stream->Read(data, size, &size);
res = _stream->Read((char*)data + tmpSize, size, &size);
_physPos += size;
}
if (processedSize)
*processedSize = size;
_virtPos += size;
*processedSize = size + tmpSize;
_virtPos += size + tmpSize;
return res;
}

Expand Down

0 comments on commit cde87a9

Please # to comment.