summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp b/3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp
index 133d95b3885..b0f222c2621 100644
--- a/3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp
+++ b/3rdparty/lzma/CPP/7zip/Common/InBuffer.cpp
@@ -7,10 +7,10 @@
#include "InBuffer.h"
CInBufferBase::CInBufferBase() throw():
- _buf(0),
- _bufLim(0),
- _bufBase(0),
- _stream(0),
+ _buf(NULL),
+ _bufLim(NULL),
+ _bufBase(NULL),
+ _stream(NULL),
_processedSize(0),
_bufSize(0),
_wasFinished(false),
@@ -22,18 +22,18 @@ bool CInBuffer::Create(size_t bufSize) throw()
const unsigned kMinBlockSize = 1;
if (bufSize < kMinBlockSize)
bufSize = kMinBlockSize;
- if (_bufBase != 0 && _bufSize == bufSize)
+ if (_bufBase != NULL && _bufSize == bufSize)
return true;
Free();
_bufSize = bufSize;
_bufBase = (Byte *)::MidAlloc(bufSize);
- return (_bufBase != 0);
+ return (_bufBase != NULL);
}
void CInBuffer::Free() throw()
{
::MidFree(_bufBase);
- _bufBase = 0;
+ _bufBase = NULL;
}
void CInBufferBase::Init() throw()
@@ -42,7 +42,7 @@ void CInBufferBase::Init() throw()
_buf = _bufBase;
_bufLim = _buf;
_wasFinished = false;
- #ifdef _NO_EXCEPTIONS
+ #ifdef Z7_NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
NumExtraBytes = 0;
@@ -50,19 +50,19 @@ void CInBufferBase::Init() throw()
bool CInBufferBase::ReadBlock()
{
- #ifdef _NO_EXCEPTIONS
+ #ifdef Z7_NO_EXCEPTIONS
if (ErrorCode != S_OK)
return false;
#endif
if (_wasFinished)
return false;
- _processedSize += (_buf - _bufBase);
+ _processedSize += (size_t)(_buf - _bufBase);
_buf = _bufBase;
_bufLim = _bufBase;
UInt32 processed;
// FIX_ME: we can improve it to support (_bufSize >= (1 << 32))
- HRESULT result = _stream->Read(_bufBase, (UInt32)_bufSize, &processed);
- #ifdef _NO_EXCEPTIONS
+ const HRESULT result = _stream->Read(_bufBase, (UInt32)_bufSize, &processed);
+ #ifdef Z7_NO_EXCEPTIONS
ErrorCode = result;
#else
if (result != S_OK)
@@ -77,7 +77,8 @@ bool CInBufferBase::ReadByte_FromNewBlock(Byte &b)
{
if (!ReadBlock())
{
- NumExtraBytes++;
+ // 22.00: we don't increment (NumExtraBytes) here
+ // NumExtraBytes++;
b = 0xFF;
return false;
}
@@ -97,6 +98,33 @@ Byte CInBufferBase::ReadByte_FromNewBlock()
size_t CInBufferBase::ReadBytes(Byte *buf, size_t size)
{
+ size_t num = 0;
+ for (;;)
+ {
+ const size_t rem = (size_t)(_bufLim - _buf);
+ if (size <= rem)
+ {
+ if (size != 0)
+ {
+ memcpy(buf, _buf, size);
+ _buf += size;
+ num += size;
+ }
+ return num;
+ }
+ if (rem != 0)
+ {
+ memcpy(buf, _buf, rem);
+ _buf += rem;
+ buf += rem;
+ num += rem;
+ size -= rem;
+ }
+ if (!ReadBlock())
+ return num;
+ }
+
+ /*
if ((size_t)(_bufLim - _buf) >= size)
{
const Byte *src = _buf;
@@ -113,6 +141,7 @@ size_t CInBufferBase::ReadBytes(Byte *buf, size_t size)
buf[i] = *_buf++;
}
return size;
+ */
}
size_t CInBufferBase::Skip(size_t size)
@@ -120,7 +149,7 @@ size_t CInBufferBase::Skip(size_t size)
size_t processed = 0;
for (;;)
{
- size_t rem = (_bufLim - _buf);
+ const size_t rem = (size_t)(_bufLim - _buf);
if (rem >= size)
{
_buf += size;