From: Yann Collet Date: Sat, 2 Jul 2016 09:14:30 +0000 (+0200) Subject: extended use of strerror(errno) X-Git-Tag: v0.7.2^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed7fb8413c3bbc5606d502af8c06b54b15de6172;p=thirdparty%2Fzstd.git extended use of strerror(errno) --- diff --git a/programs/datagen.c b/programs/datagen.c index ec118f5d1..389b5dbc7 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -29,6 +29,7 @@ #include /* malloc */ #include /* FILE, fwrite, fprintf */ #include /* memcpy */ +#include /* errno */ #include "mem.h" /* U32 */ @@ -104,7 +105,7 @@ static BYTE RDG_genChar(U32* seed, const BYTE* ldt) U32 const id = RDG_rand(seed) & LTMASK; //TRACE(" %u : \n", id); //TRACE(" %4u [%4u] ; val : %4u \n", id, id&255, ldt[id]); - return (ldt[id]); /* memory-sanitizer fails here, stating "uninitialized value" when table initialized with 0.0. Checked : table is fully initialized */ + return ldt[id]; /* memory-sanitizer fails here, stating "uninitialized value" when table initialized with P==0.0. Checked : table is fully initialized */ } @@ -115,8 +116,7 @@ static U32 RDG_rand15Bits (unsigned* seedPtr) static U32 RDG_randLength(unsigned* seedPtr) { - if (RDG_rand(seedPtr) & 7) - return (RDG_rand(seedPtr) & 0xF); + if (RDG_rand(seedPtr) & 7) return (RDG_rand(seedPtr) & 0xF); /* small length */ return (RDG_rand(seedPtr) & 0x1FF) + 0xF; } @@ -185,10 +185,10 @@ void RDG_genStdout(unsigned long long size, double matchProba, double litProba, size_t const stdDictSize = 32 KB; BYTE* const buff = (BYTE*)malloc(stdDictSize + stdBlockSize); U64 total = 0; - BYTE ldt[LTSIZE]; + BYTE ldt[LTSIZE]; /* literals distribution table */ /* init */ - if (buff==NULL) { fprintf(stdout, "not enough memory\n"); exit(1); } + if (buff==NULL) { fprintf(stderr, "datagen: error: %s \n", strerror(errno)); exit(1); } if (litProba<=0.0) litProba = matchProba / 4.5; memset(ldt, '0', sizeof(ldt)); RDG_fillLiteralDistrib(ldt, litProba); diff --git a/programs/datagencli.c b/programs/datagencli.c index d437d5cb3..ecca7015f 100644 --- a/programs/datagencli.c +++ b/programs/datagencli.c @@ -27,8 +27,8 @@ /*-************************************ * Includes **************************************/ -#include "util.h" /* Compiler options */ #include /* fprintf, stderr */ +#include "util.h" /* Compiler options */ #include "datagen.h" /* RDG_generate */ diff --git a/programs/fileio.c b/programs/fileio.c index d6a42d5b3..20fc82dba 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -240,7 +240,7 @@ static size_t FIO_loadFile(void** bufferPtr, const char* fileName) fileSize = MAX_DICT_SIZE; } *bufferPtr = malloc((size_t)fileSize); - if (*bufferPtr==NULL) EXM_THROW(34, "Allocation error : not enough memory for dictBuffer"); + if (*bufferPtr==NULL) EXM_THROW(34, "zstd: %s", strerror(errno)); { size_t const readSize = fread(*bufferPtr, 1, (size_t)fileSize, fileHandle); if (readSize!=fileSize) EXM_THROW(35, "Error reading dictionary file %s", fileName); } fclose(fileHandle); @@ -269,14 +269,14 @@ static cRess_t FIO_createCResources(const char* dictFileName) cRess_t ress; ress.ctx = ZBUFF_createCCtx(); - if (ress.ctx == NULL) EXM_THROW(30, "Allocation error : can't create ZBUFF context"); + if (ress.ctx == NULL) EXM_THROW(30, "zstd: allocation error : can't create ZBUFF context"); /* Allocate Memory */ ress.srcBufferSize = ZBUFF_recommendedCInSize(); ress.srcBuffer = malloc(ress.srcBufferSize); ress.dstBufferSize = ZBUFF_recommendedCOutSize(); ress.dstBuffer = malloc(ress.dstBufferSize); - if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); + if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "zstd: allocation error : not enough memory"); /* dictionary */ ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName); @@ -291,7 +291,7 @@ static void FIO_freeCResources(cRess_t ress) free(ress.dstBuffer); free(ress.dictBuffer); errorCode = ZBUFF_freeCCtx(ress.ctx); - if (ZBUFF_isError(errorCode)) EXM_THROW(38, "Error : can't release ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode)); + if (ZBUFF_isError(errorCode)) EXM_THROW(38, "zstd: error : can't release ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode)); }