Commit 106156cb authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

ole32: Remove some assertions in the stuctured storage code by

returning error codes to the caller and by handling the error condition.
parent 79f7318a
...@@ -3557,7 +3557,7 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks( ...@@ -3557,7 +3557,7 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
ULARGE_INTEGER size, offset; ULARGE_INTEGER size, offset;
ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten; ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten;
ULONG propertyIndex; ULONG propertyIndex;
HRESULT resWrite; HRESULT resWrite = S_OK;
HRESULT resRead; HRESULT resRead;
StgProperty chainProperty; StgProperty chainProperty;
BYTE *buffer; BYTE *buffer;
...@@ -3593,7 +3593,7 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks( ...@@ -3593,7 +3593,7 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
{ {
resRead = SmallBlockChainStream_ReadAt(*ppsbChain, resRead = SmallBlockChainStream_ReadAt(*ppsbChain,
offset, offset,
DEF_SMALL_BLOCK_SIZE, This->smallBlockSize,
buffer, buffer,
&cbRead); &cbRead);
if (FAILED(resRead)) if (FAILED(resRead))
...@@ -3618,7 +3618,12 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks( ...@@ -3618,7 +3618,12 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
} while (cbRead > 0); } while (cbRead > 0);
HeapFree(GetProcessHeap(),0,buffer); HeapFree(GetProcessHeap(),0,buffer);
assert(cbTotalRead == cbTotalWritten); if (FAILED(resRead) || FAILED(resWrite))
{
ERR("conversion failed: resRead = 0x%08lx, resWrite = 0x%08lx\n", resRead, resWrite);
BlockChainStream_Destroy(bbTempChain);
return NULL;
}
/* /*
* Destroy the small block chain. * Destroy the small block chain.
...@@ -5319,8 +5324,6 @@ HRESULT SmallBlockChainStream_ReadAt( ...@@ -5319,8 +5324,6 @@ HRESULT SmallBlockChainStream_ReadAt(
if (FAILED(rc)) if (FAILED(rc))
return rc; return rc;
assert(bytesReadFromBigBlockFile == bytesToReadInBuffer);
/* /*
* Step to the next big block. * Step to the next big block.
*/ */
...@@ -5328,10 +5331,10 @@ HRESULT SmallBlockChainStream_ReadAt( ...@@ -5328,10 +5331,10 @@ HRESULT SmallBlockChainStream_ReadAt(
if(FAILED(rc)) if(FAILED(rc))
return STG_E_DOCFILECORRUPT; return STG_E_DOCFILECORRUPT;
bufferWalker += bytesToReadInBuffer; bufferWalker += bytesReadFromBigBlockFile;
size -= bytesToReadInBuffer; size -= bytesReadFromBigBlockFile;
*bytesRead += bytesToReadInBuffer; *bytesRead += bytesReadFromBigBlockFile;
offsetInBlock = 0; /* There is no offset on the next block */ offsetInBlock = (offsetInBlock + bytesReadFromBigBlockFile) % This->parentStorage->smallBlockSize;
} }
return (size == 0) ? S_OK : STG_E_READFAULT; return (size == 0) ? S_OK : STG_E_READFAULT;
...@@ -5358,7 +5361,7 @@ HRESULT SmallBlockChainStream_WriteAt( ...@@ -5358,7 +5361,7 @@ HRESULT SmallBlockChainStream_WriteAt(
ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize; ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize;
ULONG bytesToWriteInBuffer; ULONG bytesToWriteInBuffer;
ULONG blockIndex; ULONG blockIndex;
ULONG bytesWrittenFromBigBlockFile; ULONG bytesWrittenToBigBlockFile;
const BYTE* bufferWalker; const BYTE* bufferWalker;
HRESULT res; HRESULT res;
...@@ -5412,22 +5415,20 @@ HRESULT SmallBlockChainStream_WriteAt( ...@@ -5412,22 +5415,20 @@ HRESULT SmallBlockChainStream_WriteAt(
offsetInBigBlockFile, offsetInBigBlockFile,
bytesToWriteInBuffer, bytesToWriteInBuffer,
bufferWalker, bufferWalker,
&bytesWrittenFromBigBlockFile); &bytesWrittenToBigBlockFile);
if (FAILED(res)) if (FAILED(res))
return res; return res;
assert(bytesWrittenFromBigBlockFile == bytesToWriteInBuffer);
/* /*
* Step to the next big block. * Step to the next big block.
*/ */
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex,
&blockIndex))) &blockIndex)))
return FALSE; return FALSE;
bufferWalker += bytesToWriteInBuffer; bufferWalker += bytesWrittenToBigBlockFile;
size -= bytesToWriteInBuffer; size -= bytesWrittenToBigBlockFile;
*bytesWritten += bytesToWriteInBuffer; *bytesWritten += bytesWrittenToBigBlockFile;
offsetInBlock = 0; /* There is no offset on the next block */ offsetInBlock = (offsetInBlock + bytesWrittenToBigBlockFile) % This->parentStorage->smallBlockSize;
} }
return (size == 0) ? S_OK : STG_E_WRITEFAULT; return (size == 0) ? S_OK : STG_E_WRITEFAULT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment