summaryrefslogtreecommitdiffstats
path: root/examples/frameCompress.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2016-11-21 23:44:25 (GMT)
committerYann Collet <cyan@fb.com>2016-11-21 23:44:25 (GMT)
commitba7a85b463fe6e6b2a3b9db24277054eb54a42a7 (patch)
treecd1f5d5a367fb41b039bb9f013e7b2c1c7439efe /examples/frameCompress.c
parent3bde02a059f1fba25be95c31b3e27947d80604f8 (diff)
downloadlz4-ba7a85b463fe6e6b2a3b9db24277054eb54a42a7.zip
lz4-ba7a85b463fe6e6b2a3b9db24277054eb54a42a7.tar.gz
lz4-ba7a85b463fe6e6b2a3b9db24277054eb54a42a7.tar.bz2
fixed minor analyzer warning
Diffstat (limited to 'examples/frameCompress.c')
-rw-r--r--examples/frameCompress.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/examples/frameCompress.c b/examples/frameCompress.c
index b7a3576..df41451 100644
--- a/examples/frameCompress.c
+++ b/examples/frameCompress.c
@@ -116,6 +116,7 @@ static size_t compress_file(FILE *in, FILE *out, size_t *size_in, size_t *size_o
static size_t get_block_size(const LZ4F_frameInfo_t* info) {
switch (info->blockSizeID) {
+ case LZ4F_default:
case LZ4F_max64KB: return 1 << 16;
case LZ4F_max256KB: return 1 << 18;
case LZ4F_max1MB: return 1 << 20;
@@ -127,17 +128,14 @@ static size_t get_block_size(const LZ4F_frameInfo_t* info) {
}
static size_t decompress_file(FILE *in, FILE *out) {
- void * const src = malloc(BUF_SIZE);
- void *dst = NULL;
- void *srcPtr = src;
- void *srcEnd = src;
- size_t srcSize = 0;
- size_t dstSize = 0;
+ void* const src = malloc(BUF_SIZE);
+ void* dst = NULL;
size_t dstCapacity = 0;
LZ4F_dctx *dctx = NULL;
size_t ret;
/* Initialization */
+ if (!src) { perror("decompress_file(src)"); goto cleanup; }
ret = LZ4F_createDecompressionContext(&dctx, 100);
if (LZ4F_isError(ret)) {
printf("LZ4F_dctx creation error: %s\n", LZ4F_getErrorName(ret));
@@ -147,15 +145,14 @@ static size_t decompress_file(FILE *in, FILE *out) {
/* Decompression */
ret = 1;
while (ret != 0) {
- /* INVARIANT: At this point srcPtr == srcEnd */
/* Load more input */
- srcSize = fread(src, 1, BUF_SIZE, in);
+ size_t srcSize = fread(src, 1, BUF_SIZE, in);
+ void* srcPtr = src;
+ void* srcEnd = srcPtr + srcSize;
if (srcSize == 0 || ferror(in)) {
printf("Decompress: not enough input or error reading file\n");
goto cleanup;
}
- srcPtr = src;
- srcEnd = srcPtr + srcSize;
/* Allocate destination buffer if it isn't already */
if (!dst) {
LZ4F_frameInfo_t info;
@@ -169,6 +166,7 @@ static size_t decompress_file(FILE *in, FILE *out) {
*/
dstCapacity = get_block_size(&info);
dst = malloc(dstCapacity);
+ if (!dst) { perror("decompress_file(dst)"); goto cleanup; }
srcPtr += srcSize;
srcSize = srcEnd - srcPtr;
}
@@ -179,7 +177,7 @@ static size_t decompress_file(FILE *in, FILE *out) {
*/
while (srcPtr != srcEnd && ret != 0) {
/* INVARIANT: Any data left in dst has already been written */
- dstSize = dstCapacity;
+ size_t dstSize = dstCapacity;
ret = LZ4F_decompress(dctx, dst, &dstSize, srcPtr, &srcSize, /* LZ4F_decompressOptions_t */ NULL);
if (LZ4F_isError(ret)) {
printf("Decompression error: %s\n", LZ4F_getErrorName(ret));