]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed a few visual analyzer warnings
authorYann Collet <yann.collet.73@gmail.com>
Sun, 5 Jul 2015 07:10:40 +0000 (23:10 -0800)
committerYann Collet <yann.collet.73@gmail.com>
Sun, 5 Jul 2015 07:10:40 +0000 (23:10 -0800)
lib/zstd.c
programs/fuzzer.c
programs/zstdcli.c

index b97e27fdd14c809fec1f54b0245e0350b8c0f33e..0eb0c2e785ea4aa531fa0ec330958cf9dc13ea29 100644 (file)
@@ -326,26 +326,25 @@ typedef struct ZSTD_Cctx_s
 
 ZSTD_Cctx* ZSTD_createCCtx(void)
 {
-    cctxi_t* ctx = (cctxi_t*) malloc( sizeof(cctxi_t) );
+    ZSTD_Cctx* ctx = (ZSTD_Cctx*) malloc( sizeof(ZSTD_Cctx) );
+    if (ctx==NULL) return NULL;
     ctx->seqStore.buffer = malloc(WORKPLACESIZE);
     ctx->seqStore.offsetStart = (U32*) (ctx->seqStore.buffer);
     ctx->seqStore.litStart = (BYTE*) (ctx->seqStore.offsetStart + (BLOCKSIZE>>2));
     ctx->seqStore.litLengthStart =  ctx->seqStore.litStart + BLOCKSIZE;
     ctx->seqStore.matchLengthStart = ctx->seqStore.litLengthStart + (BLOCKSIZE>>2);
     ctx->seqStore.dumpsStart = ctx->seqStore.matchLengthStart + (BLOCKSIZE>>2);
-    return (ZSTD_Cctx* )ctx;
+    return ctx;
 }
 
-void ZSTD_resetCCtx(ZSTD_Cctx*  cctx)
+void ZSTD_resetCCtx(ZSTD_Cctx* ctx)
 {
-    cctxi_t* ctx = (cctxi_t*)cctx;
     ctx->base = NULL;
     memset(ctx->hashTable, 0, HASH_TABLESIZE*4);
 }
 
-size_t ZSTD_freeCCtx(ZSTD_Cctx*  cctx)
+size_t ZSTD_freeCCtx(ZSTD_Cctx* ctx)
 {
-    cctxi_t* ctx = (cctxi_t*) (cctx);
     free(ctx->seqStore.buffer);
     free(ctx);
     return 0;
@@ -687,7 +686,6 @@ static size_t ZSTD_compressSequences(BYTE* dst, size_t maxDstSize,
     const size_t maxLSize = maxCSize > minSeqSize ? maxCSize - minSeqSize : 0;
     BYTE* seqHead;
 
-
     /* init */
     op = dst;
 
@@ -1711,7 +1709,7 @@ size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, size_t src
 *  Streaming Decompression API
 *******************************/
 
-typedef struct ZTSD_Dctx_s
+typedef struct ZSTD_Dctx_s
 {
     U32 ctx[FSE_DTABLE_SIZE_U32(LLFSELog) + FSE_DTABLE_SIZE_U32(OffFSELog) + FSE_DTABLE_SIZE_U32(MLFSELog)];
     size_t expected;
@@ -1722,10 +1720,11 @@ typedef struct ZTSD_Dctx_s
 
 ZSTD_Dctx* ZSTD_createDCtx(void)
 {
-    dctx_t* dctx = (dctx_t*)malloc(sizeof(dctx_t));
+    ZSTD_Dctx* dctx = (ZSTD_Dctx*)malloc(sizeof(ZSTD_Dctx));
+    if (dctx==NULL) return NULL;
     dctx->expected = ZSTD_frameHeaderSize;
     dctx->phase = 0;
-    return (ZSTD_Dctx*)dctx;
+    return dctx;
 }
 
 size_t ZSTD_freeDCtx(ZSTD_Dctx* dctx)
index b2dbcd3d9b56f3f9d19dc50ef9b36dbd11e3c37e..8d48dcd2dbd69ead90ab1d7bcb05ca730e6c4367 100644 (file)
@@ -206,6 +206,12 @@ static int basicUnitTests(U32 seed, double compressibility)
     CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
     compressedBuffer = malloc(ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH));
     decodedBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH);
+    if (!CNBuffer || !compressedBuffer || !decodedBuffer)
+    {
+        DISPLAY("Not enough memory, aborting\n");
+        testResult = 1;
+        goto _end;
+    }
     FUZ_generateSynthetic(CNBuffer, COMPRESSIBLE_NOISE_LENGTH, compressibility, &randState);
 
     // Basic tests
index 7e7c56754def081ac0e9152b7c6db4a917e64e29..e39266d456335265197c23f46039a6e9727e4196 100644 (file)
@@ -281,6 +281,7 @@ int main(int argc, char** argv)
         {
             size_t l = strlen(inFileName);
             dynNameSpace = (char*)calloc(1,l+5);
+            if (dynNameSpace==NULL) { DISPLAY("not enough memory\n"); exit(1); }
             strcpy(dynNameSpace, inFileName);
             strcpy(dynNameSpace+l, ZSTD_EXTENSION);
             outFileName = dynNameSpace;
@@ -292,6 +293,7 @@ int main(int argc, char** argv)
             size_t outl;
             size_t inl = strlen(inFileName);
             dynNameSpace = (char*)calloc(1,inl+1);
+            if (dynNameSpace==NULL) { DISPLAY("not enough memory\n"); exit(1); }
             outFileName = dynNameSpace;
             strcpy(dynNameSpace, inFileName);
             outl = inl;