alloc failure fix

This commit is contained in:
Irwan Djajadi 2016-04-18 15:51:32 -05:00
parent d86dc91677
commit 3e5bb67537

View File

@ -685,6 +685,10 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp
void* ctxPtr = &ctx; void* ctxPtr = &ctx;
#endif #endif
#if (HEAPMODE)
if (!ctxPtr) { return 0; }
#endif
int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration);
#if (HEAPMODE) #if (HEAPMODE)
@ -918,6 +922,10 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe
void* ctx = &ctxBody; void* ctx = &ctxBody;
#endif #endif
#if (HEAPMODE)
if (!ctx) { return 0; }
#endif
int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize);
#if (HEAPMODE) #if (HEAPMODE)
@ -935,6 +943,7 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe
LZ4_stream_t* LZ4_createStream(void) LZ4_stream_t* LZ4_createStream(void)
{ {
LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64);
if (!lz4s) { return NULL; }
LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */
LZ4_resetStream(lz4s); LZ4_resetStream(lz4s);
return lz4s; return lz4s;
@ -1489,6 +1498,7 @@ int LZ4_resetStreamState(void* state, char* inputBuffer)
void* LZ4_create (char* inputBuffer) void* LZ4_create (char* inputBuffer)
{ {
void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64); void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64);
if (!lz4ds) { return NULL; }
LZ4_init ((LZ4_stream_t_internal*)lz4ds, (BYTE*)inputBuffer); LZ4_init ((LZ4_stream_t_internal*)lz4ds, (BYTE*)inputBuffer);
return lz4ds; return lz4ds;
} }