Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Common')
-rwxr-xr-xCPP/7zip/Common/FileStreams.cpp2
-rwxr-xr-xCPP/7zip/Common/FilterCoder.cpp26
-rwxr-xr-xCPP/7zip/Common/InOutTempBuffer.cpp4
-rwxr-xr-xCPP/7zip/Common/MemBlocks.cpp7
-rwxr-xr-xCPP/7zip/Common/StreamObjects.cpp34
-rwxr-xr-xCPP/7zip/Common/StreamUtils.cpp44
-rwxr-xr-xCPP/7zip/Common/StreamUtils.h6
-rwxr-xr-xCPP/7zip/Common/VirtThread.cpp2
-rwxr-xr-xCPP/7zip/Common/VirtThread.h2
9 files changed, 65 insertions, 62 deletions
diff --git a/CPP/7zip/Common/FileStreams.cpp b/CPP/7zip/Common/FileStreams.cpp
index bebcf14c..f1fa419f 100755
--- a/CPP/7zip/Common/FileStreams.cpp
+++ b/CPP/7zip/Common/FileStreams.cpp
@@ -18,7 +18,7 @@ static inline HRESULT ConvertBoolToHRESULT(bool result)
DWORD lastError = ::GetLastError();
if (lastError == 0)
return E_FAIL;
- return lastError;
+ return HRESULT_FROM_WIN32(lastError);
#else
return result ? S_OK: E_FAIL;
#endif
diff --git a/CPP/7zip/Common/FilterCoder.cpp b/CPP/7zip/Common/FilterCoder.cpp
index fd89d0e1..58690c3d 100755
--- a/CPP/7zip/Common/FilterCoder.cpp
+++ b/CPP/7zip/Common/FilterCoder.cpp
@@ -30,11 +30,8 @@ HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 siz
if (size > remSize)
size = (UInt32)remSize;
}
- UInt32 processedSize = 0;
- RINOK(WriteStream(outStream, _buffer, size, &processedSize));
- if (size != processedSize)
- return E_FAIL;
- _nowPos64 += processedSize;
+ RINOK(WriteStream(outStream, _buffer, size));
+ _nowPos64 += size;
return S_OK;
}
@@ -51,12 +48,12 @@ STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,
while(NeedMore())
{
- UInt32 processedSize;
+ size_t processedSize = kBufferSize - bufferPos;
// Change it: It can be optimized using ReadPart
- RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));
+ RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));
- UInt32 endPos = bufferPos + processedSize;
+ UInt32 endPos = bufferPos + (UInt32)processedSize;
bufferPos = Filter->Filter(_buffer, endPos);
if (bufferPos > endPos)
@@ -149,10 +146,7 @@ STDMETHODIMP CFilterCoder::Flush()
if (Filter->Filter(_buffer, endPos) != endPos)
return E_FAIL;
}
- UInt32 processedSize;
- RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));
- if (_bufferPos != processedSize)
- return E_FAIL;
+ RINOK(WriteStream(_outStream, _buffer, _bufferPos));
_bufferPos = 0;
}
CMyComPtr<IOutStreamFlush> flush;
@@ -196,11 +190,9 @@ STDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
_buffer[i] = _buffer[i + _convertedPosEnd];
_bufferPos = i;
_convertedPosBegin = _convertedPosEnd = 0;
- UInt32 processedSizeTemp;
- UInt32 size0 = kBufferSize - _bufferPos;
- // Optimize it:
- RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));
- _bufferPos = _bufferPos + processedSizeTemp;
+ size_t processedSizeTemp = kBufferSize - _bufferPos;
+ RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));
+ _bufferPos = _bufferPos + (UInt32)processedSizeTemp;
_convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
if (_convertedPosEnd == 0)
{
diff --git a/CPP/7zip/Common/InOutTempBuffer.cpp b/CPP/7zip/Common/InOutTempBuffer.cpp
index ffaed32c..4cc0b2f2 100755
--- a/CPP/7zip/Common/InOutTempBuffer.cpp
+++ b/CPP/7zip/Common/InOutTempBuffer.cpp
@@ -92,7 +92,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
if (_currentPositionInBuffer < _bufferPosition)
{
UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
- RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite, NULL));
+ RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));
_currentPositionInBuffer += sizeToWrite;
}
if (!_tmpFileCreated)
@@ -104,7 +104,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
return E_FAIL;
if (localProcessedSize == 0)
return S_OK;
- RINOK(WriteStream(stream, _buffer, localProcessedSize, NULL));
+ RINOK(WriteStream(stream, _buffer, localProcessedSize));
}
}
diff --git a/CPP/7zip/Common/MemBlocks.cpp b/CPP/7zip/Common/MemBlocks.cpp
index 15702957..53f55242 100755
--- a/CPP/7zip/Common/MemBlocks.cpp
+++ b/CPP/7zip/Common/MemBlocks.cpp
@@ -125,13 +125,10 @@ HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStr
UInt32 curSize = (UInt32)blockSize;
if (totalSize < curSize)
curSize = (UInt32)totalSize;
- UInt32 processedSize;
if (blockIndex >= Blocks.Size())
return E_FAIL;
- RINOK(WriteStream(outStream, Blocks[blockIndex], curSize, &processedSize));
- if (processedSize != curSize)
- return E_FAIL;
- totalSize -= processedSize;
+ RINOK(WriteStream(outStream, Blocks[blockIndex], curSize));
+ totalSize -= curSize;
}
return S_OK;
}
diff --git a/CPP/7zip/Common/StreamObjects.cpp b/CPP/7zip/Common/StreamObjects.cpp
index 32f8f306..95d1c878 100755
--- a/CPP/7zip/Common/StreamObjects.cpp
+++ b/CPP/7zip/Common/StreamObjects.cpp
@@ -8,11 +8,13 @@
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);
- memmove(data, _dataPointer + _pos, numBytesToRead);
- _pos += numBytesToRead;
- if(processedSize != NULL)
- *processedSize = numBytesToRead;
+ size_t rem = _size - _pos;
+ if (size < rem)
+ rem = (size_t)size;
+ memcpy(data, _dataPointer + _pos, rem);
+ _pos += rem;
+ if (processedSize != NULL)
+ *processedSize = (UInt32)rem;
return S_OK;
}
@@ -21,13 +23,13 @@ void CWriteBuffer::Write(const void *data, size_t size)
{
size_t newCapacity = _size + size;
_buffer.EnsureCapacity(newCapacity);
- memmove(_buffer + _size, data, size);
+ memcpy(_buffer + _size, data, size);
_size += size;
}
STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
- _writeBuffer.Write(data, size);
+ _writeBuffer.Write(data, (size_t)size);
if(processedSize != NULL)
*processedSize = size;
return S_OK;
@@ -35,16 +37,14 @@ STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt3
STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 newSize = size;
- if (_pos + size > _size)
- newSize = (UInt32)(_size - _pos);
- memmove(_buffer + _pos, data, newSize);
- if(processedSize != NULL)
- *processedSize = newSize;
- _pos += newSize;
- if (newSize != size)
- return E_FAIL;
- return S_OK;
+ size_t rem = _size - _pos;
+ if (size < rem)
+ rem = (size_t)size;
+ memcpy(_buffer + _pos, data, rem);
+ _pos += rem;
+ if (processedSize != NULL)
+ *processedSize = (UInt32)rem;
+ return (rem == size ? S_OK : E_FAIL);
}
STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
diff --git a/CPP/7zip/Common/StreamUtils.cpp b/CPP/7zip/Common/StreamUtils.cpp
index 1d951271..9cde2c40 100755
--- a/CPP/7zip/Common/StreamUtils.cpp
+++ b/CPP/7zip/Common/StreamUtils.cpp
@@ -2,20 +2,21 @@
#include "StdAfx.h"
-#include "../../Common/MyCom.h"
#include "StreamUtils.h"
-HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
+static const UInt32 kBlockSize = ((UInt32)1 << 31);
+
+HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)
{
- if (processedSize != 0)
- *processedSize = 0;
- while(size != 0)
+ size_t size = *processedSize;
+ *processedSize = 0;
+ while (size != 0)
{
+ UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
UInt32 processedSizeLoc;
- HRESULT res = stream->Read(data, size, &processedSizeLoc);
- if (processedSize != 0)
- *processedSize += processedSizeLoc;
- data = (Byte *)((Byte *)data + processedSizeLoc);
+ HRESULT res = stream->Read(data, curSize, &processedSizeLoc);
+ *processedSize += processedSizeLoc;
+ data = (void *)((Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
if (processedSizeLoc == 0)
@@ -24,16 +25,27 @@ HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32
return S_OK;
}
-HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
+HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)
+{
+ size_t processedSize = size;
+ RINOK(ReadStream(stream, data, &processedSize));
+ return (size == processedSize) ? S_OK : S_FALSE;
+}
+
+HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)
+{
+ size_t processedSize = size;
+ RINOK(ReadStream(stream, data, &processedSize));
+ return (size == processedSize) ? S_OK : E_FAIL;
+}
+
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)
{
- if (processedSize != 0)
- *processedSize = 0;
- while(size != 0)
+ while (size != 0)
{
+ UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
UInt32 processedSizeLoc;
- HRESULT res = stream->Write(data, size, &processedSizeLoc);
- if (processedSize != 0)
- *processedSize += processedSizeLoc;
+ HRESULT res = stream->Write(data, curSize, &processedSizeLoc);
data = (const void *)((const Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
diff --git a/CPP/7zip/Common/StreamUtils.h b/CPP/7zip/Common/StreamUtils.h
index 59f88733..f1cfd184 100755
--- a/CPP/7zip/Common/StreamUtils.h
+++ b/CPP/7zip/Common/StreamUtils.h
@@ -5,7 +5,9 @@
#include "../IStream.h"
-HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
-HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
+HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);
+HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);
+HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);
#endif
diff --git a/CPP/7zip/Common/VirtThread.cpp b/CPP/7zip/Common/VirtThread.cpp
index 3567f98e..f12581ad 100755
--- a/CPP/7zip/Common/VirtThread.cpp
+++ b/CPP/7zip/Common/VirtThread.cpp
@@ -17,7 +17,7 @@ static THREAD_FUNC_DECL CoderThread(void *p)
}
}
-HRes CVirtThread::Create()
+WRes CVirtThread::Create()
{
RINOK(StartEvent.CreateIfNotCreated());
RINOK(FinishedEvent.CreateIfNotCreated());
diff --git a/CPP/7zip/Common/VirtThread.h b/CPP/7zip/Common/VirtThread.h
index 62c055b6..604b090b 100755
--- a/CPP/7zip/Common/VirtThread.h
+++ b/CPP/7zip/Common/VirtThread.h
@@ -14,7 +14,7 @@ struct CVirtThread
bool ExitEvent;
~CVirtThread();
- HRes Create();
+ WRes Create();
void Start();
void WaitFinish() { FinishedEvent.Lock(); }
virtual void Execute() = 0;