From: Yann Collet Date: Sat, 22 Sep 2018 01:23:32 +0000 (-0700) Subject: fixed constant comparison on 32-bits systems X-Git-Tag: v0.0.29~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e211bdd1825a4bf695c47cb7c62cad674625982;p=thirdparty%2Fzstd.git fixed constant comparison on 32-bits systems --- diff --git a/tests/paramgrill.c b/tests/paramgrill.c index dbddd242f..68e1fbc4d 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -1183,38 +1183,42 @@ static int createContexts(contexts_t* ctx, const char* dictFileName) { size_t readSize; ctx->cctx = ZSTD_createCCtx(); ctx->dctx = ZSTD_createDCtx(); + assert(ctx->cctx != NULL); + assert(ctx->dctx != NULL); + if(dictFileName == NULL) { ctx->dictSize = 0; ctx->dictBuffer = NULL; return 0; } - ctx->dictSize = UTIL_getFileSize(dictFileName); - assert(ctx->dictSize != UTIL_FILESIZE_UNKNOWN); + { U64 const dictFileSize = UTIL_getFileSize(dictFileName); + assert(dictFileSize != UTIL_FILESIZE_UNKNOWN); + ctx->dictSize = dictFileSize; + assert((U64)ctx->dictSize == dictFileSize); /* check overflow */ + } ctx->dictBuffer = malloc(ctx->dictSize); f = fopen(dictFileName, "rb"); - if(!f) { + if (f==NULL) { DISPLAY("unable to open file\n"); - fclose(f); freeContexts(*ctx); return 1; } - if(ctx->dictSize > 64 MB || !(ctx->dictBuffer)) { + if (ctx->dictSize > 64 MB || !(ctx->dictBuffer)) { DISPLAY("dictionary too large\n"); fclose(f); freeContexts(*ctx); return 1; } readSize = fread(ctx->dictBuffer, 1, ctx->dictSize, f); - if(readSize != ctx->dictSize) { + fclose(f); + if (readSize != ctx->dictSize) { DISPLAY("unable to read file\n"); - fclose(f); freeContexts(*ctx); return 1; } - fclose(f); return 0; }