]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Reversing condition order and forwarding error
authorBimba Shrestha <bimbashrestha@fb.com>
Mon, 18 Nov 2019 21:53:55 +0000 (13:53 -0800)
committerBimba Shrestha <bimbashrestha@fb.com>
Mon, 18 Nov 2019 21:53:55 +0000 (13:53 -0800)
lib/compress/zstd_compress.c

index a883d21c18a6eed4d29a61d7d00b248061f41b5d..6330b8821634ddd1244e4fa508e02d6bb39a3d3a 100644 (file)
@@ -2480,11 +2480,13 @@ static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
          * enough for SuperBlock compression.
          * In such case, fall back to normal compression. This is possible because
          * targetCBlockSize is best effort not a guarantee. */
-        if (cSize == ERROR(dstSize_tooSmall) || (dstCapacity - cSize) < 4) {
-            /* We check (dstCapacity - cSize) < 4 above because we have to make sure
+        if (cSize != ERROR(dstSize_tooSmall) && (dstCapacity - cSize) >= 4)
+            /* We check (dstCapacity - cSize) >= 4 above because we have to make sure
              * to leave enough room for the checksum that will eventually get added in
              * the epilogue. Otherwise, we're just going to throw the dstSize_tooSmall
              * error there instead of here */
+            return cSize;
+        else {
             BYTE* const ostart = (BYTE*)dst;
             /* If ZSTD_noCompressSuperBlock fails with dstSize_tooSmall,
              * compress normally.
@@ -2497,6 +2499,7 @@ static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
                     zc->entropyWorkspace, HUF_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
                     zc->bmi2);
 
+            FORWARD_IF_ERROR(cSize);
             if (cSize == 0) {
                 /* If compressSequences didn't work, we just output a regular
                  * uncompressed block */
@@ -2507,7 +2510,7 @@ static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
                 MEM_writeLE24(ostart, cBlockHeader24);
                 cSize += ZSTD_blockHeaderSize;
             }
-        } else return cSize;
+        }
     }
 
     if (!ZSTD_isError(cSize) && cSize != 0) {