]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Avoid bad function cast by using temporary
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 17:07:44 +0000 (19:07 +0200)
committerAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 17:07:44 +0000 (19:07 +0200)
The result after round/ceil _should_ work

src/cleanup.c
src/hashtable.c

index 676afc2ed81dc74459eb7956ab1ea342ef0a01d9..0b66cafcda089649bdfbf944b0d91665c015081b 100644 (file)
@@ -164,9 +164,10 @@ clean_up_dir(struct conf *conf, const char *dir, double limit_multiple)
        // When "max files" or "max cache size" is reached, one of the 16 cache
        // subdirectories is cleaned up. When doing so, files are deleted (in LRU
        // order) until the levels are below limit_multiple.
-       cache_size_threshold = (uint64_t)round(conf->max_size * limit_multiple / 16);
-       files_in_cache_threshold =
-               (size_t)round(conf->max_files * limit_multiple / 16);
+       double cache_size_float = round(conf->max_size * limit_multiple / 16);
+       cache_size_threshold = (uint64_t)cache_size_float;
+       double files_in_cache_float = round(conf->max_files * limit_multiple / 16);
+       files_in_cache_threshold = (size_t)files_in_cache_float;
 
        num_files = 0;
        cache_size = 0;
index 19eff8f440af8ade54d175f52fec04b86aa6d9ff..308e72cab81aa8a35be280ff8892c63bd64c2f19 100644 (file)
@@ -81,7 +81,8 @@ create_hashtable(unsigned int minsize,
     h->entrycount   = 0;
     h->hashfn       = hashf;
     h->eqfn         = eqf;
-    h->loadlimit    = (unsigned int) ceilf((float) size * max_load_factor);
+    double loadlimit_float = ceil((double)size * (double)max_load_factor);
+    h->loadlimit    = (unsigned int)loadlimit_float;
     return h;
 }
 
@@ -154,7 +155,8 @@ hashtable_expand(struct hashtable *h)
         }
     }
     h->tablelength = newsize;
-    h->loadlimit   = (unsigned int) ceil(newsize * max_load_factor);
+    double loadlimit_float = ceil((double)newsize* (double)max_load_factor);
+    h->loadlimit   = (unsigned int) loadlimit_float;
     return -1;
 }