From bae60765411e2e77e46510b2fcb9fa401e5f9cc0 Mon Sep 17 00:00:00 2001 From: Piotr Dulikowski Date: Wed, 4 Sep 2024 21:21:10 +0200 Subject: [PATCH] service/qos: add constructors to service_level Add a default constructor and a constructor which explicitly initializes all fields of the service_level structure. This is done in order to make sure that removal of the marked_for_deletion field can be done safely - otherwise, for example, service_level could be aggregate-initialized with an incomplete list of values for the fields, and removing marked_for_deletion which is in the middle of the struct would cause the is_static field to be initialized with the value that was designated for marked_for_deletion. As a bonus, make sure that marked_for_deletion and is_static bool fields are initialized in the default constructor to false in order to avoid potential undefined behavior. --- service/qos/service_level_controller.cc | 2 +- service/qos/service_level_controller.hh | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/service/qos/service_level_controller.cc b/service/qos/service_level_controller.cc index bfa9afcf3c..0b936c40de 100644 --- a/service/qos/service_level_controller.cc +++ b/service/qos/service_level_controller.cc @@ -541,7 +541,7 @@ future<> service_level_controller::do_add_service_level(sstring name, service_le return make_ready_future(); } } else { - return do_with(service_level{.slo = slo, .is_static = is_static}, std::move(name), [this] (service_level& sl, sstring& name) { + return do_with(service_level(slo, false, is_static), std::move(name), [this] (service_level& sl, sstring& name) { return container().invoke_on_all(&service_level_controller::notify_service_level_added, name, sl); }); } diff --git a/service/qos/service_level_controller.hh b/service/qos/service_level_controller.hh index ecb89018d4..b76da1cba5 100644 --- a/service/qos/service_level_controller.hh +++ b/service/qos/service_level_controller.hh @@ -42,8 +42,16 @@ namespace qos { */ struct service_level { service_level_options slo; - bool marked_for_deletion; - bool is_static; + bool marked_for_deletion = false; + bool is_static = false; + + service_level() = default; + + service_level(service_level_options slo, bool marked_for_deletion, bool is_static) + : slo(std::move(slo)) + , marked_for_deletion(marked_for_deletion) + , is_static(is_static) + {} }; using update_both_cache_levels = bool_class;