ensure a ptr is non-null
authorYann Collet <cyan@fb.com>
Sun, 14 Jan 2018 06:47:46 +0000 (22:47 -0800)
committerYann Collet <cyan@fb.com>
Sun, 14 Jan 2018 06:47:46 +0000 (22:47 -0800)
with an assert()
to help static analyzer understanding this condition.

lib/lz4frame.c

index 62e7010..b5c868f 100644 (file)
@@ -70,6 +70,14 @@ You can contact the author at :
 /*-************************************
 *  Debug
 **************************************/
+#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1)
+#  include <assert.h>
+#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)