]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Agree on types between dump and backend
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Oct 2021 14:37:04 +0000 (15:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Oct 2021 14:37:04 +0000 (15:37 +0100)
lualib/rspamadm/statistics_dump.lua
src/libstat/backends/cdb_backend.cxx

index 33b2a3cc58d79964516ff2eb3185d80c0c47cffd..aa461a92a90ed730ce02a7e9bb8622e986955739 100644 (file)
@@ -266,7 +266,7 @@ local function dump_pattern(conn, pattern, opts, out, key)
         if opts.cdb then
           table.insert(out[key].elts, {
             key = rspamd_i64.fromstring(string.match(d.key, '%d+')),
-            value = rspamd_util.pack('<n<n', tonumber(d.data["S"] or '0') or 0,
+            value = rspamd_util.pack('ff', tonumber(d.data["S"] or '0') or 0,
                 tonumber(d.data["H"] or '0'))
           })
         else
index 5e1ec243bf5ec1060a5a59131909f881eac3e6d0..15c3d30350dc1463f66e08edd02ac07fc1f1e993 100644 (file)
@@ -145,7 +145,7 @@ private:
 
 template<typename T>
 static inline auto
-cdb_get_key_as_double(struct cdb *cdb, T key) -> std::optional<double>
+cdb_get_key_as_int64(struct cdb *cdb, T key) -> std::optional<std::int64_t>
 {
        auto pos = cdb_find(cdb, (void *)&key, sizeof(key));
 
@@ -153,8 +153,8 @@ cdb_get_key_as_double(struct cdb *cdb, T key) -> std::optional<double>
                auto vpos = cdb_datapos(cdb);
                auto vlen = cdb_datalen(cdb);
 
-               if (vlen == sizeof(double)) {
-                       double ret;
+               if (vlen == sizeof(std::int64_t)) {
+                       std::int64_t ret;
                        cdb_read(cdb, (void *)&ret, vlen, vpos);
 
                        return ret;
@@ -206,13 +206,12 @@ ro_backend::load_cdb() -> tl::expected<bool, std::string>
        auto check_key = [&](const char *key, std::uint64_t &target) -> tl::expected<bool, std::string> {
                memcpy((void *)&cdb_key, key, sizeof(cdb_key));
 
-               auto maybe_value = cdb_get_key_as_double(db.get(), cdb_key);
+               auto maybe_value = cdb_get_key_as_int64(db.get(), cdb_key);
 
                if (!maybe_value) {
                        return tl::make_unexpected(fmt::format("missing {} key", key));
                }
 
-               // Convert from double to int
                target = (std::uint64_t)maybe_value.value();
 
                return true;