]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils/cache_gc: more lint fixes
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 17 Jun 2019 11:31:17 +0000 (13:31 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:22 +0000 (15:59 +0200)
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
utils/cache_gc/kr_cache_gc.c

index bfdb465c010dfb09de3c0596a560be53b2313eec..b50cffc1b200e16b1e14326cdaa01aeff17c959b 100644 (file)
@@ -1,6 +1,7 @@
 #include "categories.h"
 
 #include <libknot/libknot.h>
+#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
index e74ff332acdb9613319239590709d8454ec36ff6..9c6886b34128b875346056d29ba927685f640410 100644 (file)
@@ -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);