From 3e5bb67537da4e93c13fdaf9ae5d04b0afef3c5a Mon Sep 17 00:00:00 2001 From: Irwan Djajadi Date: Mon, 18 Apr 2016 15:51:32 -0500 Subject: alloc failure fix --- lib/lz4.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/lz4.c b/lib/lz4.c index 08cf6b5..5f8359e 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -685,6 +685,10 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp void* ctxPtr = &ctx; #endif +#if (HEAPMODE) + if (!ctxPtr) { return 0; } +#endif + int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); #if (HEAPMODE) @@ -918,6 +922,10 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe void* ctx = &ctxBody; #endif +#if (HEAPMODE) + if (!ctx) { return 0; } +#endif + int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); #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* 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_resetStream(lz4s); return lz4s; @@ -1489,6 +1498,7 @@ int LZ4_resetStreamState(void* state, char* inputBuffer) void* LZ4_create (char* inputBuffer) { void* lz4ds = ALLOCATOR(8, LZ4_STREAMSIZE_U64); + if (!lz4ds) { return NULL; } LZ4_init ((LZ4_stream_t_internal*)lz4ds, (BYTE*)inputBuffer); return lz4ds; } -- cgit v0.12 From 10e3eecc566440eaad65a74063527d194ec0133a Mon Sep 17 00:00:00 2001 From: Irwan Djajadi Date: Tue, 19 Apr 2016 15:01:35 -0500 Subject: fixed non-C99 compiler --- lib/lz4.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 5f8359e..55b5089 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -684,12 +684,13 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp LZ4_stream_t ctx; void* ctxPtr = &ctx; #endif + int result; #if (HEAPMODE) if (!ctxPtr) { return 0; } #endif - int result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); + result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); #if (HEAPMODE) FREEMEM(ctxPtr); @@ -829,7 +830,7 @@ _next_match: /* Match description too long : reduce it */ matchLength = (15-1) + (oMaxMatch-op) * 255; } - //printf("offset %5i, matchLength%5i \n", (int)(ip-match), matchLength + MINMATCH); + /*printf("offset %5i, matchLength%5i \n", (int)(ip-match), matchLength + MINMATCH);*/ ip += MINMATCH + matchLength; if (matchLength>=ML_MASK) @@ -921,12 +922,13 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe LZ4_stream_t ctxBody; void* ctx = &ctxBody; #endif + int result; #if (HEAPMODE) if (!ctx) { return 0; } #endif - int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); + result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); #if (HEAPMODE) FREEMEM(ctx); -- cgit v0.12