From 0e211bdd1825a4bf695c47cb7c62cad674625982 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Sep 2018 18:23:32 -0700 Subject: [PATCH] fixed constant comparison on 32-bits systems --- tests/paramgrill.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/paramgrill.c b/tests/paramgrill.c index dbddd242..68e1fbc4 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; }