]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
streaming compression example can handle situations where input buffer size is manual...
authorYann Collet <yann.collet.73@gmail.com>
Sun, 18 Sep 2016 10:17:51 +0000 (12:17 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Sun, 18 Sep 2016 10:19:06 +0000 (12:19 +0200)
examples/streaming_compression.c

index bc81af1a3fb09ab20b0753897bd391a7a002aab6..d663a4914246cf64831b45106ef4320821af1567 100644 (file)
@@ -81,6 +81,7 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
         while (input.pos < input.size) {
             ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
             toRead = ZSTD_compressStream(cstream, &output , &input);   /* toRead is guaranteed to be <= ZSTD_CStreamInSize() */
+            if (toRead > buffInSize) toRead = buffInSize;   /* Safely handle when `buffInSize` is manually changed to a smaller value */
             fwrite_orDie(buffOut, output.pos, fout);
         }
     }