From 4f09abfb149d1692e6747f64dbca28c8d71cd320 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 17 Jun 2019 13:31:17 +0200 Subject: [PATCH] utils/cache_gc: more lint fixes I can't see any real benefit of floating-point in the amount_tofree computation; we could use round(), but it doesn't seem significant. --- utils/cache_gc/categories.c | 5 ++++- utils/cache_gc/kr_cache_gc.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/cache_gc/categories.c b/utils/cache_gc/categories.c index bfdb465c0..b50cffc1b 100644 --- a/utils/cache_gc/categories.c +++ b/utils/cache_gc/categories.c @@ -1,6 +1,7 @@ #include "categories.h" #include +#include "lib/utils.h" static bool rrtype_is_infrastructure(uint16_t r) { @@ -18,7 +19,9 @@ static bool rrtype_is_infrastructure(uint16_t r) static int get_random(int to) { - return rand() % to; + // We don't need these to be really unpredictable, + // but this should be cheap enough not to be noticeable. + return kr_rand_bytes(1) % to; } // TODO this is just an example, make this more clever diff --git a/utils/cache_gc/kr_cache_gc.c b/utils/cache_gc/kr_cache_gc.c index e74ff332a..9c6886b34 100644 --- a/utils/cache_gc/kr_cache_gc.c +++ b/utils/cache_gc/kr_cache_gc.c @@ -165,7 +165,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) return ret; } - ssize_t amount_tofree = (double)knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed / 100.0; + ssize_t amount_tofree = knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed / 100; // debug /*printf("tofree: %zd\n", amount_tofree); -- 2.47.2