summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2018-09-16 19:07:44 +0200
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2018-09-16 19:07:44 +0200
commitc46da15589b971981435e11be31f9f2ccae1bb77 (patch)
tree87f6962fa0a5cca26693f52cf9d8b64a2c0e692c
parent063c3718d8ccb6b4007ec46329b425db30a40b39 (diff)
downloadccache-c46da15589b971981435e11be31f9f2ccae1bb77.tar.gz
Avoid bad function cast by using temporary
The result after round/ceil _should_ work
-rw-r--r--src/cleanup.c7
-rw-r--r--src/hashtable.c6
2 files changed, 8 insertions, 5 deletions
diff --git a/src/cleanup.c b/src/cleanup.c
index 676afc2e..0b66cafc 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 19eff8f4..308e72ca 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;
}