fixed context copy
This commit is contained in:
parent
ecd651bd91
commit
6e1c4c6c65
@ -69,7 +69,7 @@ extern "C" {
|
|||||||
#define ERROR_LIST(ITEM) \
|
#define ERROR_LIST(ITEM) \
|
||||||
ITEM(PREFIX(No_Error)) ITEM(PREFIX(GENERIC)) \
|
ITEM(PREFIX(No_Error)) ITEM(PREFIX(GENERIC)) \
|
||||||
ITEM(PREFIX(prefix_unknown)) ITEM(PREFIX(frameParameter_unsupported)) ITEM(PREFIX(frameParameter_unsupportedBy32bitsImplementation)) \
|
ITEM(PREFIX(prefix_unknown)) ITEM(PREFIX(frameParameter_unsupported)) ITEM(PREFIX(frameParameter_unsupportedBy32bitsImplementation)) \
|
||||||
ITEM(PREFIX(init_missing)) ITEM(PREFIX(memory_allocation)) \
|
ITEM(PREFIX(init_missing)) ITEM(PREFIX(memory_allocation)) ITEM(PREFIX(stage_wrong)) \
|
||||||
ITEM(PREFIX(dstSize_tooSmall)) ITEM(PREFIX(srcSize_wrong)) \
|
ITEM(PREFIX(dstSize_tooSmall)) ITEM(PREFIX(srcSize_wrong)) \
|
||||||
ITEM(PREFIX(corruption_detected)) \
|
ITEM(PREFIX(corruption_detected)) \
|
||||||
ITEM(PREFIX(tableLog_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooSmall)) \
|
ITEM(PREFIX(tableLog_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooSmall)) \
|
||||||
|
@ -1963,11 +1963,17 @@ size_t ZSTD_duplicateCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx)
|
|||||||
{
|
{
|
||||||
void* dstWorkSpace = dstCCtx->workSpace;
|
void* dstWorkSpace = dstCCtx->workSpace;
|
||||||
size_t dstWorkSpaceSize = dstCCtx->workSpaceSize;
|
size_t dstWorkSpaceSize = dstCCtx->workSpaceSize;
|
||||||
|
const U32 contentLog = (srcCCtx->params.strategy == ZSTD_fast) ? 1 : srcCCtx->params.contentLog;
|
||||||
|
const size_t tableSpace = ((1 << contentLog) + (1 << srcCCtx->params.hashLog)) * sizeof(U32);
|
||||||
|
const size_t blockSize = MIN(BLOCKSIZE, (size_t)1 << srcCCtx->params.windowLog);
|
||||||
|
const size_t neededSpace = tableSpace + (3*blockSize);
|
||||||
|
|
||||||
if (dstWorkSpaceSize < srcCCtx->workSpaceSize)
|
if (srcCCtx->stage!=0) return ERROR(stage_wrong);
|
||||||
|
|
||||||
|
if (dstWorkSpaceSize < neededSpace)
|
||||||
{
|
{
|
||||||
free(dstCCtx->workSpace);
|
free(dstWorkSpace);
|
||||||
dstWorkSpaceSize = srcCCtx->workSpaceSize;
|
dstWorkSpaceSize = neededSpace;
|
||||||
dstWorkSpace = malloc(dstWorkSpaceSize);
|
dstWorkSpace = malloc(dstWorkSpaceSize);
|
||||||
if (dstWorkSpace==NULL) return ERROR(memory_allocation);
|
if (dstWorkSpace==NULL) return ERROR(memory_allocation);
|
||||||
}
|
}
|
||||||
@ -1976,6 +1982,8 @@ size_t ZSTD_duplicateCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx)
|
|||||||
dstCCtx->workSpace = dstWorkSpace;
|
dstCCtx->workSpace = dstWorkSpace;
|
||||||
dstCCtx->workSpaceSize = dstWorkSpaceSize;
|
dstCCtx->workSpaceSize = dstWorkSpaceSize;
|
||||||
|
|
||||||
|
memcpy(dstWorkSpace, srcCCtx->workSpace, tableSpace);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user