From: Jérémie Galarneau Date: Tue, 6 Jun 2023 17:43:28 +0000 (-0400) Subject: Fix clang-tidy cppcoreguidelines-pro-type-const-cast warning X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=commitdiff_plain;h=1e0019bb584561d6d93ec74b72b2f673dd661f9d Fix clang-tidy cppcoreguidelines-pro-type-const-cast warning clang-tidy reports: cppcoreguidelines-pro-type-const-cast; do not use const_cast The const_cast adds a const qualifier so this warning seems a bit strict. Regardless, we can dodge the whole question by passing the exclusion_list as `const char * const *`, which is closer to the original intention of the API anyhow. For more information on the safety of these types of casts, see: https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion Signed-off-by: Jérémie Galarneau Change-Id: Ia3129b7d1ed4e450f3f2d63920d2fd67c66a6d73 --- diff --git a/include/lttng/event-internal.hpp b/include/lttng/event-internal.hpp index 830b00a50..3d8893b69 100644 --- a/include/lttng/event-internal.hpp +++ b/include/lttng/event-internal.hpp @@ -162,7 +162,7 @@ ssize_t lttng_event_create_from_payload(struct lttng_payload_view *view, int lttng_event_serialize(const struct lttng_event *event, unsigned int exclusion_count, - const char **exclusion_list, + const char *const *exclusion_list, const char *filter_expression, size_t bytecode_len, struct lttng_bytecode *bytecode, diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index ef4383ff2..c9924b326 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -496,16 +496,14 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name, * We do not care about the filter bytecode and the fd from the * userspace_probe_location. */ - ret = lttng_event_serialize( - tmp_event, - exclusion_names.size(), - exclusion_names.size() ? - exclusion_names.data() : - nullptr, - uevent->filter_expression, - 0, - nullptr, - reply_payload); + ret = lttng_event_serialize(tmp_event, + exclusion_names.size(), + exclusion_names.size() ? exclusion_names.data() : + nullptr, + uevent->filter_expression, + 0, + nullptr, + reply_payload); lttng_event_destroy(tmp_event); if (ret) { ret_code = LTTNG_ERR_FATAL; diff --git a/src/common/event.cpp b/src/common/event.cpp index 47c0bcbf7..dfcc52bc5 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -664,7 +664,7 @@ end: int lttng_event_serialize(const struct lttng_event *event, unsigned int exclusion_count, - const char **exclusion_list, + const char *const *exclusion_list, const char *filter_expression, size_t bytecode_len, struct lttng_bytecode *bytecode, diff --git a/src/lib/lttng-ctl/lttng-ctl.cpp b/src/lib/lttng-ctl/lttng-ctl.cpp index 03ed2aa10..15a699e24 100644 --- a/src/lib/lttng-ctl/lttng-ctl.cpp +++ b/src/lib/lttng-ctl/lttng-ctl.cpp @@ -1180,7 +1180,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, serialize: ret = lttng_event_serialize(ev, exclusion_count, - const_cast(exclusion_list), + exclusion_list, filter_expression, bytecode_len, (ctx && bytecode_len) ? &ctx->bytecode->b : nullptr,