From: Vladimír Čunát Date: Mon, 17 Jun 2019 11:31:17 +0000 (+0200) Subject: utils/cache_gc: more lint fixes X-Git-Tag: v4.1.0^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f09abfb149d1692e6747f64dbca28c8d71cd320;p=thirdparty%2Fknot-resolver.git 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. --- 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);