From: Anders F Björklund Date: Sun, 16 Sep 2018 17:07:44 +0000 (+0200) Subject: Avoid bad function cast by using temporary X-Git-Tag: v3.5~26^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c46da15589b971981435e11be31f9f2ccae1bb77;p=thirdparty%2Fccache.git Avoid bad function cast by using temporary The result after round/ceil _should_ work --- diff --git a/src/cleanup.c b/src/cleanup.c index 676afc2ed..0b66cafcd 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -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; diff --git a/src/hashtable.c b/src/hashtable.c index 19eff8f44..308e72cab 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -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; }