]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix compiler narrowing warning 426/head
authorNick Terrell <terrelln@fb.com>
Mon, 24 Oct 2016 21:11:27 +0000 (14:11 -0700)
committerNick Terrell <terrelln@fb.com>
Mon, 24 Oct 2016 21:50:13 +0000 (14:50 -0700)
lib/compress/zstd_compress.c

index 1d4450aa55cfc70eaf5e49364894470e67a1ae73..6922aab6cbf65bcbdd65d6df1ed8152a9bcb5f62 100644 (file)
@@ -2523,9 +2523,12 @@ static size_t ZSTD_loadDictEntropyStats(ZSTD_CCtx* cctx, const void* dict, size_
     cctx->rep[2] = MEM_readLE32(dictPtr+8); if (cctx->rep[2] >= dictSize) return ERROR(dictionary_corrupted);
     dictPtr += 12;
 
-    {   size_t const maxOffset = (dictEnd - dictPtr) + 128 KB; /* The maximum offset that must be supported */
-        /* Calculate minimum offset code required to represent maxOffset */
-        unsigned const offcodeMax = ZSTD_highbit32(maxOffset);
+    {   U32 offcodeMax = MaxOff;
+        if ((size_t)(dictEnd - dictPtr) <= ((U32)-1) - 128 KB) {
+            U32 const maxOffset = (U32)(dictEnd - dictPtr) + 128 KB; /* The maximum offset that must be supported */
+            /* Calculate minimum offset code required to represent maxOffset */
+            offcodeMax = ZSTD_highbit32(maxOffset);
+        }
         /* Every possible supported offset <= dictContentSize + 128 KB must be representable */
         CHECK_F (ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff)));
     }