diff options
author | alk3pInjection <webmaster@raspii.tech> | 2021-08-30 16:43:38 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2021-08-30 16:43:38 +0800 |
commit | cbe033a53bfe49d980774e59025e3b2af91778b7 (patch) | |
tree | 558535f91276162e0be70d07b34ed2e6577e38ad /examples/frameCompress.c | |
parent | fdd43c66dd9e77283aa8f7e52a881be44d622441 (diff) | |
parent | d44371841a2f1728a3f36839fd4b7e872d0927d3 (diff) |
Merge tag 'v1.9.3' into lineage-18.1HEADlineage-18.1
Change-Id: Iad56c1b17a32f9f356a4c1ff9557f0e79addf481
Diffstat (limited to 'examples/frameCompress.c')
-rw-r--r-- | examples/frameCompress.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/examples/frameCompress.c b/examples/frameCompress.c index a0c5d3d..aac4a3b 100644 --- a/examples/frameCompress.c +++ b/examples/frameCompress.c @@ -32,12 +32,12 @@ static void safe_fwrite(void* buf, size_t eltSize, size_t nbElt, FILE* f) { size_t const writtenSize = fwrite(buf, eltSize, nbElt, f); size_t const expectedSize = eltSize * nbElt; - assert(expectedSize / nbElt == eltSize); /* check overflow */ + if (nbElt>0) assert(expectedSize / nbElt == eltSize); /* check overflow */ if (writtenSize < expectedSize) { if (ferror(f)) /* note : ferror() must follow fwrite */ fprintf(stderr, "Write failed \n"); else - fprintf(stderr, "Short write \n"); + fprintf(stderr, "Write too short \n"); exit(1); } } @@ -70,11 +70,12 @@ compress_file_internal(FILE* f_in, FILE* f_out, /* write frame header */ { size_t const headerSize = LZ4F_compressBegin(ctx, outBuff, outCapacity, &kPrefs); if (LZ4F_isError(headerSize)) { - printf("Failed to start compression: error %zu\n", headerSize); + printf("Failed to start compression: error %u \n", (unsigned)headerSize); return result; } count_out = headerSize; - printf("Buffer size is %zu bytes, header size %zu bytes\n", outCapacity, headerSize); + printf("Buffer size is %u bytes, header size %u bytes \n", + (unsigned)outCapacity, (unsigned)headerSize); safe_fwrite(outBuff, 1, headerSize, f_out); } @@ -89,11 +90,11 @@ compress_file_internal(FILE* f_in, FILE* f_out, inBuff, readSize, NULL); if (LZ4F_isError(compressedSize)) { - printf("Compression failed: error %zu\n", compressedSize); + printf("Compression failed: error %u \n", (unsigned)compressedSize); return result; } - printf("Writing %zu bytes\n", compressedSize); + printf("Writing %u bytes\n", (unsigned)compressedSize); safe_fwrite(outBuff, 1, compressedSize, f_out); count_out += compressedSize; } @@ -103,11 +104,11 @@ compress_file_internal(FILE* f_in, FILE* f_out, outBuff, outCapacity, NULL); if (LZ4F_isError(compressedSize)) { - printf("Failed to end compression: error %zu\n", compressedSize); + printf("Failed to end compression: error %u \n", (unsigned)compressedSize); return result; } - printf("Writing %zu bytes\n", compressedSize); + printf("Writing %u bytes \n", (unsigned)compressedSize); safe_fwrite(outBuff, 1, compressedSize, f_out); count_out += compressedSize; } @@ -184,8 +185,8 @@ decompress_file_internal(FILE* f_in, FILE* f_out, while (ret != 0) { /* Load more input */ size_t readSize = firstChunk ? filled : fread(src, 1, srcCapacity, f_in); firstChunk=0; - const void* srcPtr = src + alreadyConsumed; alreadyConsumed=0; - const void* const srcEnd = srcPtr + readSize; + const void* srcPtr = (const char*)src + alreadyConsumed; alreadyConsumed=0; + const void* const srcEnd = (const char*)srcPtr + readSize; if (readSize == 0 || ferror(f_in)) { printf("Decompress: not enough input or error reading file\n"); return 1; @@ -198,7 +199,7 @@ decompress_file_internal(FILE* f_in, FILE* f_out, while (srcPtr < srcEnd && ret != 0) { /* Any data within dst has been flushed at this stage */ size_t dstSize = dstCapacity; - size_t srcSize = srcEnd - srcPtr; + size_t srcSize = (const char*)srcEnd - (const char*)srcPtr; ret = LZ4F_decompress(dctx, dst, &dstSize, srcPtr, &srcSize, /* LZ4F_decompressOptions_t */ NULL); if (LZ4F_isError(ret)) { printf("Decompression error: %s\n", LZ4F_getErrorName(ret)); @@ -207,7 +208,7 @@ decompress_file_internal(FILE* f_in, FILE* f_out, /* Flush output */ if (dstSize != 0) safe_fwrite(dst, 1, dstSize, f_out); /* Update input */ - srcPtr += srcSize; + srcPtr = (const char*)srcPtr + srcSize; } assert(srcPtr <= srcEnd); |