]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed constant comparison on 32-bits systems
authorYann Collet <cyan@fb.com>
Sat, 22 Sep 2018 01:23:32 +0000 (18:23 -0700)
committerYann Collet <cyan@fb.com>
Sat, 22 Sep 2018 01:23:32 +0000 (18:23 -0700)
tests/paramgrill.c

index dbddd242f78170e08e95802974de6660eea43225..68e1fbc4de4d4ca1de0d9a467942de177742d513 100644 (file)
@@ -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;
 }