From: Yann Collet Date: Sun, 5 Jul 2015 07:10:40 +0000 (-0800) Subject: Fixed a few visual analyzer warnings X-Git-Tag: v0.1.0~3^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94f998b1fc1034c8cdc58850755279b3e5288eaa;p=thirdparty%2Fzstd.git Fixed a few visual analyzer warnings --- diff --git a/lib/zstd.c b/lib/zstd.c index b97e27fdd..0eb0c2e78 100644 --- a/lib/zstd.c +++ b/lib/zstd.c @@ -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) diff --git a/programs/fuzzer.c b/programs/fuzzer.c index b2dbcd3d9..8d48dcd2d 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -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 diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 7e7c56754..e39266d45 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -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;