commit a8e0f75: [Minor] Agree on types between dump and backend
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Oct 21 14:42:07 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-10-21 15:37:04 +0100
URL: https://github.com/rspamd/rspamd/commit/a8e0f75aa6df80fd27ea25f40307f3892a991c8f (HEAD -> master)
[Minor] Agree on types between dump and backend
---
lualib/rspamadm/statistics_dump.lua | 2 +-
src/libstat/backends/cdb_backend.cxx | 9 ++++-----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/lualib/rspamadm/statistics_dump.lua b/lualib/rspamadm/statistics_dump.lua
index 33b2a3cc5..aa461a92a 100644
--- a/lualib/rspamadm/statistics_dump.lua
+++ b/lualib/rspamadm/statistics_dump.lua
@@ -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
diff --git a/src/libstat/backends/cdb_backend.cxx b/src/libstat/backends/cdb_backend.cxx
index 5e1ec243b..15c3d3035 100644
--- a/src/libstat/backends/cdb_backend.cxx
+++ b/src/libstat/backends/cdb_backend.cxx
@@ -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;
More information about the Commits
mailing list