]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
add an assert 4344/head
authorYann Collet <yann.collet.73@gmail.com>
Sun, 23 Mar 2025 01:23:31 +0000 (18:23 -0700)
committerYann Collet <yann.collet.73@gmail.com>
Sun, 23 Mar 2025 01:23:31 +0000 (18:23 -0700)
to help static analyzers understand there is no overflow risk there.

lib/compress/huf_compress.c

index ea000723209f97ef87d8e4191bc42ec22dc6ee25..6f2194e7934846af1e7808fea41d18e6227c4481 100644 (file)
@@ -425,6 +425,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 targetNbBits
                  * gain back half the rank.
                  */
                 U32 nBitsToDecrease = ZSTD_highbit32((U32)totalCost) + 1;
+                assert(nBitsToDecrease <= HUF_TABLELOG_MAX+1);
                 for ( ; nBitsToDecrease > 1; nBitsToDecrease--) {
                     U32 const highPos = rankLast[nBitsToDecrease];
                     U32 const lowPos = rankLast[nBitsToDecrease-1];