]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added test that exposes zero offset to null pointer error when built with clang
authorDanielle Rozenblit <drozenblit@fb.com>
Wed, 7 Sep 2022 15:58:08 +0000 (08:58 -0700)
committerDanielle Rozenblit <drozenblit@fb.com>
Wed, 7 Sep 2022 15:58:08 +0000 (08:58 -0700)
tests/zstreamtest.c

index d4c9823e2ff6d5af9859a1f3d47307b489d1b905..04a75f09e1c4c966771f6765b957566503b26b1c 100644 (file)
@@ -548,14 +548,33 @@ static int basicUnitTests(U32 seed, double compressibility)
     {   size_t const ret = ZSTD_decompressStream(zd, &outBuff, &inBuff);
         if (ret != 0) goto _output_error;
     }
-    inBuff.src = NULL;
-    inBuff.size = 0;
-    inBuff.pos = 0;
-    outBuff.dst = NULL;
-    outBuff.size = 0;
-    outBuff.pos = 0;
-    CHECK_Z( ZSTD_initDStream(zd) );
-    CHECK_Z(ZSTD_decompressStream(zd, &outBuff, &inBuff));
+
+    {
+        const char* test = "aa";
+        inBuff.src = test;
+        inBuff.size = 2;
+        inBuff.pos = 0;
+        outBuff.dst = NULL;
+        outBuff.size = 0;
+        outBuff.pos = 0;
+        CHECK_Z( ZSTD_compressStream(zc, &outBuff, &inBuff) );
+        CHECK(inBuff.pos != inBuff.size, "Entire input should be consumed");
+        CHECK_Z( ZSTD_endStream(zc, &outBuff) );
+        outBuff.dst = (char*)(compressedBuffer);
+        outBuff.size = compressedBufferSize;
+        outBuff.pos = 0;
+        {   size_t const r = ZSTD_endStream(zc, &outBuff);
+            CHECK(r != 0, "Error or some data not flushed (ret=%zu)", r);
+        }
+        inBuff.src = outBuff.dst;
+        inBuff.size = outBuff.pos;
+        inBuff.pos = 0;
+        outBuff.dst = NULL;
+        outBuff.size = 0;
+        outBuff.pos = 0;
+        CHECK_Z( ZSTD_initDStream(zd) );
+        CHECK_Z(ZSTD_decompressStream(zd, &outBuff, &inBuff));
+    }
 
     DISPLAYLEVEL(3, "OK\n");
     /* _srcSize compression test */