From 3243aab573813d1d8cc286f8b510ceafb5917324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Tue, 30 Jun 2026 16:50:12 +0100 Subject: [PATCH] Avoid exception in user resource comparison --- src/user_resource.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/user_resource.hpp b/src/user_resource.hpp index 93381c973..b0ce64e1b 100644 --- a/src/user_resource.hpp +++ b/src/user_resource.hpp @@ -9,11 +9,10 @@ #include "memory_resource.hpp" #include #include -#include namespace ddwaf::memory { -class user_resource : public memory::memory_resource { +class user_resource final : public memory::memory_resource { public: using alloc_fn_type = void *(*)(void *, size_t, size_t); using free_fn_type = void (*)(void *, void *, size_t, size_t); @@ -27,6 +26,10 @@ class user_resource : public memory::memory_resource { throw std::invalid_argument("undefined user alloc/free function"); } } + user_resource(const user_resource &) = delete; + user_resource(user_resource &&) = delete; + user_resource &operator=(const user_resource &) = delete; + user_resource &operator=(user_resource &&) = delete; ~user_resource() override { @@ -50,12 +53,11 @@ class user_resource : public memory::memory_resource { { // Two memory_resources compare equal if and only if memory allocated from one // memory_resource can be deallocated from the other and vice versa. - try { - const auto &user_mr = dynamic_cast(other); - return free_fn_ == user_mr.free_fn_; - } catch (const std::bad_cast &) { + const auto *user_mr = dynamic_cast(&other); + if (user_mr == nullptr) { return false; } + return free_fn_ == user_mr->free_fn_; } alloc_fn_type alloc_fn_;