From 4fec726c4d352daf2fb4a7e5ed463e44c8815ddb Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Sun, 16 Nov 2025 23:21:29 +0200 Subject: [PATCH] refactor: Simplify Interpret asmap function This aligns it more with SanityCheckAsmap and reduces variable scope. Also unify asmap casing in SanityCheckAsmap function name. Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com> --- src/test/fuzz/asmap_direct.cpp | 4 ++-- src/util/asmap.cpp | 24 +++++++++++------------- src/util/asmap.h | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/test/fuzz/asmap_direct.cpp b/src/test/fuzz/asmap_direct.cpp index fa77553282e..a338c1336f4 100644 --- a/src/test/fuzz/asmap_direct.cpp +++ b/src/test/fuzz/asmap_direct.cpp @@ -51,7 +51,7 @@ FUZZ_TARGET(asmap_direct) // Checks on asmap auto asmap = BitsToBytes(buffer.first(sep_pos)); - if (SanityCheckASMap(asmap, ip_len)) { + if (SanityCheckAsmap(asmap, ip_len)) { // Verify that for valid asmaps, no prefix (except up to 7 zero padding bits) is valid. for (size_t prefix_len = sep_pos - 1; prefix_len > 0; --prefix_len) { auto prefix = BitsToBytes(buffer.first(prefix_len)); @@ -59,7 +59,7 @@ FUZZ_TARGET(asmap_direct) // asmap, since they will contain some zero padding bits in the last // byte. if (prefix.size() == asmap.size()) continue; - assert(!SanityCheckASMap(prefix, ip_len)); + assert(!SanityCheckAsmap(prefix, ip_len)); } // No address input should trigger assertions in interpreter diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp index ed1d3b0be4b..4d4ed4fe869 100644 --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -186,18 +186,16 @@ uint32_t Interpret(const std::span asmap, const std::span= static_cast(endpos - pos)) break; // Jumping past EOF @@ -210,11 +208,11 @@ uint32_t Interpret(const std::span asmap, const std::span> (matchlen - 1 - bit)) & 1)) { return default_asn; // Pattern mismatch - use default } @@ -229,7 +227,7 @@ uint32_t Interpret(const std::span asmap, const std::span asmap, const std::span asmap, int bits) +bool SanityCheckAsmap(const std::span asmap, int bits) { size_t pos{0}; const size_t endpos{asmap.size() * 8}; @@ -311,7 +309,7 @@ bool SanityCheckASMap(const std::span asmap, int bits) */ bool CheckStandardAsmap(const std::span data) { - if (!SanityCheckASMap(data, 128)) { + if (!SanityCheckAsmap(data, 128)) { LogWarning("Sanity check of asmap data failed\n"); return false; } diff --git a/src/util/asmap.h b/src/util/asmap.h index 1d5f6e81187..5d65e219318 100644 --- a/src/util/asmap.h +++ b/src/util/asmap.h @@ -15,7 +15,7 @@ uint32_t Interpret(std::span asmap, std::span ip); -bool SanityCheckASMap(std::span asmap, int bits); +bool SanityCheckAsmap(std::span asmap, int bits); /** Check standard asmap data (128 bits for IPv6) */ bool CheckStandardAsmap(std::span data);