From: inikep Date: Fri, 3 Jun 2016 11:23:04 +0000 (+0200) Subject: removed calloc calls from lib/ X-Git-Tag: v0.7.0^2~49^2~21^2^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36fac00149638196286928b8fef8c54f65897b3c;p=thirdparty%2Fzstd.git removed calloc calls from lib/ --- diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index a1004fba3..05cf69657 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -59,7 +59,6 @@ /* ************************************************************** * Includes ****************************************************************/ -#include /* malloc, free, qsort */ #include /* memcpy, memset */ #include /* printf (debug) */ #include "huf_static.h" diff --git a/lib/compress/zbuff_compress.c b/lib/compress/zbuff_compress.c index 0ec27ad70..1681bc84a 100644 --- a/lib/compress/zbuff_compress.c +++ b/lib/compress/zbuff_compress.c @@ -108,13 +108,7 @@ ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem) ZBUFF_CCtx* zbc; if (!customMem.customAlloc && !customMem.customFree) - { - zbc = (ZBUFF_CCtx*)calloc(1, sizeof(ZBUFF_CCtx)); - if (zbc==NULL) return NULL; - memcpy(&zbc->customMem, &defaultCustomMem, sizeof(ZSTD_customMem)); - zbc->zc = ZSTD_createCCtx(); - return zbc; - } + customMem = defaultCustomMem; if (!customMem.customAlloc || !customMem.customFree) return NULL; diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 93caee0d7..3196916f9 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -51,7 +51,6 @@ /*-************************************* * Dependencies ***************************************/ -#include /* malloc */ #include /* memset */ #include "mem.h" #define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ @@ -130,12 +129,7 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) ZSTD_CCtx* ctx; if (!customMem.customAlloc && !customMem.customFree) - { - ctx = (ZSTD_CCtx*) calloc(1, sizeof(ZSTD_CCtx)); - if (!ctx) return NULL; - memcpy(&ctx->customMem, &defaultCustomMem, sizeof(ZSTD_customMem)); - return ctx; - } + customMem = defaultCustomMem; if (!customMem.customAlloc || !customMem.customFree) return NULL; diff --git a/lib/decompress/huf_decompress.c b/lib/decompress/huf_decompress.c index 01e9c07b2..14afbb927 100644 --- a/lib/decompress/huf_decompress.c +++ b/lib/decompress/huf_decompress.c @@ -59,7 +59,6 @@ /* ************************************************************** * Includes ****************************************************************/ -#include /* malloc, free, qsort */ #include /* memcpy, memset */ #include /* printf (debug) */ #include "huf_static.h" diff --git a/lib/decompress/zbuff_decompress.c b/lib/decompress/zbuff_decompress.c index 4dfb2adae..01fcc217f 100644 --- a/lib/decompress/zbuff_decompress.c +++ b/lib/decompress/zbuff_decompress.c @@ -96,14 +96,7 @@ ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem) ZBUFF_DCtx* zbd; if (!customMem.customAlloc && !customMem.customFree) - { - zbd = (ZBUFF_DCtx*)calloc(1, sizeof(ZBUFF_DCtx)); - if (zbd==NULL) return NULL; - memcpy(&zbd->customMem, &defaultCustomMem, sizeof(ZSTD_customMem)); - zbd->zd = ZSTD_createDCtx(); - zbd->stage = ZBUFFds_init; - return zbd; - } + customMem = defaultCustomMem; if (!customMem.customAlloc || !customMem.customFree) return NULL; diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index d4426bcca..495e8d296 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -53,7 +53,6 @@ /*-******************************************************* * Dependencies *********************************************************/ -#include /* calloc */ #include /* memcpy, memmove */ #include /* debug only : printf */ #include "mem.h" /* low level memory routines */ @@ -152,13 +151,8 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem) { ZSTD_DCtx* dctx; - if (!customMem.customAlloc && !customMem.customFree) { - dctx = (ZSTD_DCtx*) malloc(sizeof(ZSTD_DCtx)); - if (!dctx) return NULL; - memcpy(&dctx->customMem, &defaultCustomMem, sizeof(ZSTD_customMem)); - ZSTD_decompressBegin(dctx); - return dctx; - } + if (!customMem.customAlloc && !customMem.customFree) + customMem = defaultCustomMem; if (!customMem.customAlloc || !customMem.customFree) return NULL; diff --git a/programs/zbufftest.c b/programs/zbufftest.c index 37a941791..387119815 100644 --- a/programs/zbufftest.c +++ b/programs/zbufftest.c @@ -521,6 +521,7 @@ int main(int argc, const char** argv) U32 mainPause = 0; const char* programName = argv[0]; ZSTD_customMem customMem = { ZBUFF_allocFunction, ZBUFF_freeFunction, NULL }; + ZSTD_customMem customNULL = { NULL, NULL, NULL }; /* Check command line */ for(argNb=1; argNb