make scan-build accept assert()
authorYann Collet <yann.collet.73@gmail.com>
Thu, 1 Oct 2020 17:48:22 +0000 (10:48 -0700)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 1 Oct 2020 17:48:22 +0000 (10:48 -0700)
Makefile
lib/lz4frame.c

index c1869f682302428bc6984f3abfc8688059743692..a45611c2e84a42e487394bd0a63e041dff8d849f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,7 @@ usan32: clean
 
 .PHONY: staticAnalyze
 staticAnalyze: clean
-       CFLAGS=-g scan-build --status-bugs -v $(MAKE) all
+       CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g scan-build --status-bugs -v --force-analyze-debug-code $(MAKE) all V=1 DEBUGLEVEL=1
 
 .PHONY: cppcheck
 cppcheck:
index 2c62d7854d85bb9213f3cfbf0f7e250f9063b669..bfdef5d5d5f0246fa20dc825166e60b4c9c562e5 100644 (file)
@@ -1284,18 +1284,20 @@ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_dctx* dctx,
 
 
 /* LZ4F_updateDict() :
- * only used for LZ4F_blockLinked mode */
+ * only used for LZ4F_blockLinked mode
+ * Condition : dstPtr != NULL
+ */
 static void LZ4F_updateDict(LZ4F_dctx* dctx,
                       const BYTE* dstPtr, size_t dstSize, const BYTE* dstBufferStart,
                       unsigned withinTmp)
 {
-    /* hint to static analyzer : dstPtr can't be NULL at this stage */
-    assert(dstPtr != NULL); if (dstPtr==NULL) return;
+    assert(dstPtr != NULL);
     if (dctx->dictSize==0) {
-        dctx->dict = (const BYTE*)dstPtr;   /* priority to dictionary continuity */
+        dctx->dict = (const BYTE*)dstPtr;   /* priority to prefix mode */
     }
+    assert(dctx->dict != NULL);
 
-    if (dctx->dict + dctx->dictSize == dstPtr) {  /* dictionary continuity, directly within dstBuffer */
+    if (dctx->dict + dctx->dictSize == dstPtr) {  /* prefix mode, everything within dstBuffer */
         dctx->dictSize += dstSize;
         return;
     }
@@ -1309,7 +1311,8 @@ static void LZ4F_updateDict(LZ4F_dctx* dctx,
 
     assert(dstSize < 64 KB);   /* if dstSize >= 64 KB, dictionary would be set into dstBuffer directly */
 
-    /* dstBuffer does not contain whole useful history (64 KB), so it must be saved within tmpOut */
+    /* dstBuffer does not contain whole useful history (64 KB), so it must be saved within tmpOutBuffer */
+    assert(dctx->tmpOutBuffer != NULL);
 
     if (withinTmp && (dctx->dict == dctx->tmpOutBuffer)) {   /* continue history within tmpOutBuffer */
         /* withinTmp expectation : content of [dstPtr,dstSize] is same as [dict+dictSize,dstSize], so we just extend it */