added ZWRAP_finish_with_error
This commit is contained in:
parent
6101687547
commit
0bb930b128
@ -351,15 +351,23 @@ size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZWRAP_finish_with_error(ZWRAP_DCtx* zwd, z_streamp strm, int error)
|
||||||
|
{
|
||||||
|
if (zwd) ZWRAP_freeDCtx(zwd);
|
||||||
|
strm->state = NULL;
|
||||||
|
return (error) ? error : Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
||||||
const char *version, int stream_size))
|
const char *version, int stream_size))
|
||||||
{
|
{
|
||||||
ZWRAP_DCtx* zwd = ZWRAP_createDCtx(strm);
|
ZWRAP_DCtx* zwd = ZWRAP_createDCtx(strm);
|
||||||
LOG_WRAPPER("- inflateInit\n");
|
LOG_WRAPPER("- inflateInit\n");
|
||||||
if (zwd == NULL) { strm->state = NULL; return Z_MEM_ERROR; }
|
if (zwd == NULL) return ZWRAP_finish_with_error(zwd, strm, 0);
|
||||||
|
|
||||||
zwd->version = zwd->customMem.customAlloc(zwd->customMem.opaque, strlen(version) + 1);
|
zwd->version = zwd->customMem.customAlloc(zwd->customMem.opaque, strlen(version) + 1);
|
||||||
if (zwd->version == NULL) { ZWRAP_freeDCtx(zwd); strm->state = NULL; return Z_MEM_ERROR; }
|
if (zwd->version == NULL) return ZWRAP_finish_with_error(zwd, strm, 0);
|
||||||
strcpy(zwd->version, version);
|
strcpy(zwd->version, version);
|
||||||
|
|
||||||
zwd->stream_size = stream_size;
|
zwd->stream_size = stream_size;
|
||||||
@ -396,7 +404,7 @@ ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
|
|||||||
ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
|
ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
|
||||||
if (strm->state == NULL) return Z_MEM_ERROR;
|
if (strm->state == NULL) return Z_MEM_ERROR;
|
||||||
errorCode = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength);
|
errorCode = ZSTD_initDStream_usingDict(zwd->zbd, dictionary, dictLength);
|
||||||
if (ZSTD_isError(errorCode)) { ZWRAP_freeDCtx(zwd); strm->state = NULL; return Z_MEM_ERROR; }
|
if (ZSTD_isError(errorCode)) return ZWRAP_finish_with_error(zwd, strm, 0);
|
||||||
|
|
||||||
if (strm->total_in == ZSTD_HEADERSIZE) {
|
if (strm->total_in == ZSTD_HEADERSIZE) {
|
||||||
zwd->inBuffer.src = zwd->headerBuf;
|
zwd->inBuffer.src = zwd->headerBuf;
|
||||||
@ -409,8 +417,7 @@ ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
|
|||||||
LOG_WRAPPER("ZSTD_decompressStream3 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
|
LOG_WRAPPER("ZSTD_decompressStream3 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
|
||||||
if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) {
|
if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) {
|
||||||
LOG_WRAPPER("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
|
LOG_WRAPPER("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
|
||||||
ZWRAP_freeDCtx(zwd); strm->state = NULL;
|
return ZWRAP_finish_with_error(zwd, strm, 0);
|
||||||
return Z_MEM_ERROR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,7 +459,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
else
|
else
|
||||||
errorCode = inflateInit_(strm, zwd->version, zwd->stream_size);
|
errorCode = inflateInit_(strm, zwd->version, zwd->stream_size);
|
||||||
LOG_WRAPPER("ZLIB inflateInit errorCode=%d\n", (int)errorCode);
|
LOG_WRAPPER("ZLIB inflateInit errorCode=%d\n", (int)errorCode);
|
||||||
if (errorCode != Z_OK) { ZWRAP_freeDCtx(zwd); strm->state = NULL; return errorCode; }
|
if (errorCode != Z_OK) return ZWRAP_finish_with_error(zwd, strm, (int)errorCode);
|
||||||
|
|
||||||
/* inflate header */
|
/* inflate header */
|
||||||
strm->next_in = (unsigned char*)zwd->headerBuf;
|
strm->next_in = (unsigned char*)zwd->headerBuf;
|
||||||
@ -460,7 +467,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
strm->avail_out = 0;
|
strm->avail_out = 0;
|
||||||
errorCode = inflate(strm, Z_NO_FLUSH);
|
errorCode = inflate(strm, Z_NO_FLUSH);
|
||||||
LOG_WRAPPER("ZLIB inflate errorCode=%d strm->avail_in=%d\n", (int)errorCode, (int)strm->avail_in);
|
LOG_WRAPPER("ZLIB inflate errorCode=%d strm->avail_in=%d\n", (int)errorCode, (int)strm->avail_in);
|
||||||
if (errorCode != Z_OK) { ZWRAP_freeDCtx(zwd); strm->state = NULL; return errorCode; }
|
if (errorCode != Z_OK) return ZWRAP_finish_with_error(zwd, strm, (int)errorCode);
|
||||||
if (strm->avail_in > 0) goto error;
|
if (strm->avail_in > 0) goto error;
|
||||||
|
|
||||||
strm->next_in = strm2.next_in;
|
strm->next_in = strm2.next_in;
|
||||||
@ -537,9 +544,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
|
|||||||
if (errorCode == 0) return Z_STREAM_END;
|
if (errorCode == 0) return Z_STREAM_END;
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
error:
|
error:
|
||||||
ZWRAP_freeDCtx(zwd);
|
return ZWRAP_finish_with_error(zwd, strm, 0);
|
||||||
strm->state = NULL;
|
|
||||||
return Z_MEM_ERROR;
|
|
||||||
}
|
}
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user