From 03f006a7eabf476a6424821753337fefc6984dae Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 1 Oct 2020 10:48:22 -0700 Subject: [PATCH] make scan-build accept assert() --- Makefile | 2 +- lib/lz4frame.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c1869f6..a45611c 100644 --- 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: diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 2c62d78..bfdef5d 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -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 */