Fix clang-tidy cppcoreguidelines-pro-type-const-cast warning
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 6 Jun 2023 17:43:28 +0000 (13:43 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 6 Jun 2023 17:49:39 +0000 (13:49 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: Ia3129b7d1ed4e450f3f2d63920d2fd67c66a6d73

include/lttng/event-internal.hpp
src/bin/lttng-sessiond/cmd.cpp
src/common/event.cpp
src/lib/lttng-ctl/lttng-ctl.cpp

index 830b00a50aabefa7a5050df284a01b15ea1e7167..3d8893b698defe82902d1208cefc3d6600be2004 100644 (file)
@@ -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,
index ef4383ff25a67262c2f6d5157422a916d94a9147..c9924b326190dd4e765ff81af7175bf00a0b1410 100644 (file)
@@ -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;
index 47c0bcbf7e39f8ad32a8cf6c615987dfc263ae6d..dfcc52bc52a71cd810bb51dca67cac851bf20eb6 100644 (file)
@@ -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,
index 03ed2aa10a4459891018fe038b7a8cbdbaf50c75..15a699e24f3fd63837edbc6b11dccfa3ac5b1a10 100644 (file)
@@ -1180,7 +1180,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
 serialize:
        ret = lttng_event_serialize(ev,
                                    exclusion_count,
-                                   const_cast<const char **>(exclusion_list),
+                                   exclusion_list,
                                    filter_expression,
                                    bytecode_len,
                                    (ctx && bytecode_len) ? &ctx->bytecode->b : nullptr,
This page took 0.030003 seconds and 4 git commands to generate.