From 18b4c66d257a583b09e85243d21a23638b618411 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 13 Jan 2018 22:47:46 -0800 Subject: [PATCH] ensure a ptr is non-null with an assert() to help static analyzer understanding this condition. --- lib/lz4frame.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 62e7010..b5c868f 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -70,6 +70,14 @@ You can contact the author at : /*-************************************ * Debug **************************************/ +#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1) +# include +#else +# ifndef assert +# define assert(condition) ((void)0) +# endif +#endif + #define LZ4F_STATIC_ASSERT(c) { enum { LZ4F_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */ @@ -1439,6 +1447,7 @@ size_t LZ4F_decompress(LZ4F_dctx* dctx, case dstage_decodeCBlock: if (dctx->frameInfo.blockChecksumFlag) { dctx->tmpInTarget -= 4; + assert(selectedIn != NULL); /* selectedIn is defined at this stage (either srcPtr, or dctx->tmpIn) */ { U32 const readBlockCrc = LZ4F_readLE32(selectedIn + dctx->tmpInTarget); U32 const calcBlockCrc = XXH32(selectedIn, dctx->tmpInTarget, 0); if (readBlockCrc != calcBlockCrc) -- 2.7.4