src.ctf.fs: remove goto error handling from fs.cpp
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 9 Apr 2024 21:09:47 +0000 (17:09 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
gotos prevent declaring variables in the middle of functions, which is
sometimes necessary in C++.  Remove gotos used for error handling,
replace them with returning directly.

Change-Id: I15b5d6aa4897e5326fc03e2626045c83258d8eca
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8318
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12339
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/fs.cpp

index 65e9e64442886c68fdcade83c2e37913a234fa10..d78aa3db66fb6c649eed3dda41e6f1d868d3a8f0 100644 (file)
@@ -86,7 +86,6 @@ ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const
                      uint64_t capacity, uint64_t *count)
 {
     try {
-        bt_message_iterator_class_next_method_status status;
         struct ctf_fs_msg_iter_data *msg_iter_data =
             (struct ctf_fs_msg_iter_data *) bt_self_message_iterator_get_data(iterator);
         uint64_t i = 0;
@@ -98,10 +97,11 @@ ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const
          * it now.
          */
             BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(msg_iter_data->next_saved_error);
-            status = msg_iter_data->next_saved_status;
-            goto end;
+            return msg_iter_data->next_saved_status;
         }
 
+        bt_message_iterator_class_next_method_status status;
+
         do {
             status = ctf_fs_iterator_next_one(msg_iter_data, &msgs[i]);
             if (status == BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK) {
@@ -137,7 +137,6 @@ ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const
             status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
         }
 
-end:
         return status;
         return status;
     } catch (const std::bad_alloc&) {
@@ -197,7 +196,6 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
 {
     try {
         struct ctf_fs_port_data *port_data;
-        bt_message_iterator_class_initialize_method_status status;
         enum ctf_msg_iter_medium_status medium_status;
 
         port_data = (struct ctf_fs_port_data *) bt_self_component_port_get_data(
@@ -216,8 +214,7 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
         if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger,
                                          "Failed to create ctf_fs_ds_group_medops");
-            status = ctf_msg_iter_medium_status_to_msg_iter_initialize_status(medium_status);
-            goto error;
+            return ctf_msg_iter_medium_status_to_msg_iter_initialize_status(medium_status);
         }
 
         msg_iter_data->msg_iter = ctf_msg_iter_create(
@@ -228,8 +225,7 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
         if (!msg_iter_data->msg_iter) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger,
                                          "Cannot create a CTF message iterator.");
-            status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
-            goto error;
+            return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
         }
 
         /*
@@ -242,14 +238,7 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
 
         bt_self_message_iterator_set_data(self_msg_iter, msg_iter_data.release());
 
-        status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
-        goto end;
-
-error:
-        bt_self_message_iterator_set_data(self_msg_iter, NULL);
-
-end:
-        return status;
+        return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
     } catch (const std::bad_alloc&) {
         return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
     } catch (const bt2::Error&) {
@@ -310,49 +299,38 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
                                      struct ctf_fs_ds_file_group *ds_file_group,
                                      bt_self_component_source *self_comp_src)
 {
-    int ret = 0;
-    ctf_fs_port_data::UP port_data;
-
     const auto port_name = ctf_fs_make_port_name(ds_file_group);
+    auto port_data = bt2s::make_unique<ctf_fs_port_data>();
+
     BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name);
 
-    /* Create output port for this file */
-    port_data = bt2s::make_unique<ctf_fs_port_data>();
     port_data->ctf_fs = ctf_fs;
     port_data->ds_file_group = ds_file_group;
-    ret = bt_self_component_source_add_output_port(self_comp_src, port_name.c_str(),
-                                                   port_data.get(), NULL);
+
+    int ret = bt_self_component_source_add_output_port(self_comp_src, port_name.c_str(),
+                                                       port_data.get(), NULL);
     if (ret) {
-        goto error;
+        return ret;
     }
 
     ctf_fs->port_data.emplace_back(std::move(port_data));
-    goto end;
-
-error:
-    ret = -1;
-
-end:
-    return ret;
+    return 0;
 }
 
 static int create_ports_for_trace(struct ctf_fs_component *ctf_fs,
                                   struct ctf_fs_trace *ctf_fs_trace,
                                   bt_self_component_source *self_comp_src)
 {
-    int ret = 0;
-
     /* Create one output port for each stream file group */
     for (const auto& ds_file_group : ctf_fs_trace->ds_file_groups) {
-        ret = create_one_port_for_trace(ctf_fs, ds_file_group.get(), self_comp_src);
+        int ret = create_one_port_for_trace(ctf_fs, ds_file_group.get(), self_comp_src);
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Cannot create output port.");
-            goto end;
+            return ret;
         }
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 /*
@@ -445,7 +423,6 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     int64_t begin_ns = -1;
     struct ctf_fs_ds_file_group *ds_file_group = NULL;
     ctf_fs_ds_file_group::UP new_ds_file_group;
-    int ret;
     ctf_fs_ds_file_info::UP ds_file_info;
     ctf_fs_ds_index::UP index;
     ctf_msg_iter_up msg_iter;
@@ -459,7 +436,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     const auto ds_file =
         ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger);
     if (!ds_file) {
-        goto error;
+        return -1;
     }
 
     /* Create a temporary iterator to read the ds_file. */
@@ -469,17 +446,17 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
         ctf_fs_ds_file_medops, ds_file.get(), nullptr, ctf_fs_trace->logger);
     if (!msg_iter) {
         BT_CPPLOGE_STR_SPEC(ctf_fs_trace->logger, "Cannot create a CTF message iterator.");
-        goto error;
+        return -1;
     }
 
     ctf_msg_iter_set_dry_run(msg_iter.get(), true);
 
-    ret = ctf_msg_iter_get_packet_properties(msg_iter.get(), &props);
+    int ret = ctf_msg_iter_get_packet_properties(msg_iter.get(), &props);
     if (ret) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             ctf_fs_trace->logger,
             "Cannot get stream file's first packet's header and context fields (`{}`).", path);
-        goto error;
+        return ret;
     }
 
     sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc, props.stream_class_id);
@@ -496,20 +473,20 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
             BT_CPPLOGE_APPEND_CAUSE_SPEC(
                 ctf_fs_trace->logger,
                 "Cannot convert clock cycles to nanoseconds from origin (`{}`).", path);
-            goto error;
+            return ret;
         }
     }
 
     ds_file_info = ctf_fs_ds_file_info_create(path, begin_ns);
     if (!ds_file_info) {
-        goto error;
+        return -1;
     }
 
     index = ctf_fs_ds_file_build_index(ds_file.get(), ds_file_info.get(), msg_iter.get());
     if (!index) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'",
                                      ds_file->file->path);
-        goto error;
+        return -1;
     }
 
     if (begin_ns == -1) {
@@ -533,12 +510,12 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
             ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), std::move(index));
 
         if (!new_ds_file_group) {
-            goto error;
+            return -1;
         }
 
         ds_file_group_insert_ds_file_info_sorted(new_ds_file_group.get(), std::move(ds_file_info));
         ctf_fs_trace->ds_file_groups.emplace_back(std::move(new_ds_file_group));
-        goto end;
+        return 0;
     }
 
     BT_ASSERT(stream_instance_id != -1);
@@ -556,7 +533,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
         new_ds_file_group =
             ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, std::move(index));
         if (!new_ds_file_group) {
-            goto error;
+            return -1;
         }
 
         ds_file_group = new_ds_file_group.get();
@@ -567,18 +544,11 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
 
     ds_file_group_insert_ds_file_info_sorted(ds_file_group, std::move(ds_file_info));
 
-    goto end;
-
-error:
-    ret = -1;
-
-end:
-    return ret;
+    return 0;
 }
 
 static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
 {
-    int ret = 0;
     const char *basename;
     GError *error = NULL;
 
@@ -588,7 +558,10 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger,
                                      "Cannot open directory `{}`: {} (code {})", ctf_fs_trace->path,
                                      error->message, error->code);
-        goto error;
+        if (error) {
+            g_error_free(error);
+        }
+        return -1;
     }
 
     while ((basename = g_dir_read_name(dir.get()))) {
@@ -618,11 +591,11 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
             continue;
         }
 
-        ret = ctf_fs_file_open(&file, "rb");
+        int ret = ctf_fs_file_open(&file, "rb");
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Cannot open stream file `{}`",
                                          file.path);
-            goto error;
+            return ret;
         }
 
         if (file.size == 0) {
@@ -636,26 +609,15 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger,
                                          "Cannot add stream file `{}` to stream file group",
                                          file.path);
-            goto error;
+            return ret;
         }
     }
 
-    goto end;
-
-error:
-    ret = -1;
-
-end:
-    if (error) {
-        g_error_free(error);
-    }
-
-    return ret;
+    return 0;
 }
 
 static int set_trace_name(bt_trace *trace, const char *name_suffix)
 {
-    int ret = 0;
     const bt_value *val;
     std::string name;
 
@@ -676,15 +638,7 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix)
         name += name_suffix;
     }
 
-    ret = bt_trace_set_name(trace, name.c_str());
-    if (ret) {
-        goto end;
-    }
-
-    goto end;
-
-end:
-    return ret;
+    return bt_trace_set_name(trace, name.c_str());
 }
 
 static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name,
@@ -692,21 +646,19 @@ static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name,
                                             bt_self_component *selfComp,
                                             const bt2c::Logger& parentLogger)
 {
-    int ret;
-    ctf_fs_trace::UP ctf_fs_trace {new struct ctf_fs_trace(parentLogger)};
-
+    ctf_fs_trace::UP ctf_fs_trace = bt2s::make_unique<struct ctf_fs_trace>(parentLogger);
     ctf_fs_trace->path = path;
     ctf_fs_trace->metadata = bt2s::make_unique<ctf_fs_metadata>();
 
-    ret = ctf_fs_metadata_set_trace_class(selfComp, ctf_fs_trace.get(), clkClsCfg);
+    int ret = ctf_fs_metadata_set_trace_class(selfComp, ctf_fs_trace.get(), clkClsCfg);
     if (ret) {
-        goto error;
+        return nullptr;
     }
 
     if (ctf_fs_trace->metadata->trace_class) {
         bt_trace *trace = bt_trace_create(ctf_fs_trace->metadata->trace_class->libObjPtr());
         if (!trace) {
-            goto error;
+            return nullptr;
         }
 
         ctf_fs_trace->trace = bt2::Trace::Shared::createWithoutRef(trace);
@@ -716,26 +668,20 @@ static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name,
         ret = ctf_trace_class_configure_ir_trace(ctf_fs_trace->metadata->tc,
                                                  ctf_fs_trace->trace->libObjPtr());
         if (ret) {
-            goto error;
+            return nullptr;
         }
 
         ret = set_trace_name(ctf_fs_trace->trace->libObjPtr(), name);
         if (ret) {
-            goto error;
+            return nullptr;
         }
     }
 
     ret = create_ds_file_groups(ctf_fs_trace.get());
     if (ret) {
-        goto error;
+        return nullptr;
     }
 
-    goto end;
-
-error:
-    ctf_fs_trace.reset();
-
-end:
     return ctf_fs_trace;
 }
 
@@ -759,26 +705,25 @@ static int ctf_fs_component_create_ctf_fs_trace_one_path(struct ctf_fs_component
     bt2c::GStringUP norm_path {bt_common_normalize_path(path_param, NULL)};
     if (!norm_path) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to normalize path: `{}`.", path_param);
-        goto error;
+        return -1;
     }
 
     ret = path_is_ctf_trace(norm_path->str);
     if (ret < 0) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             ctf_fs->logger, "Failed to check if path is a CTF trace: path={}", norm_path->str);
-        goto error;
+        return ret;
     } else if (ret == 0) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             ctf_fs->logger, "Path is not a CTF trace (does not contain a metadata file): `{}`.",
             norm_path->str);
-        goto error;
+        return -1;
     }
 
     // FIXME: Remove or ifdef for __MINGW32__
     if (strcmp(norm_path->str, "/") == 0) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Opening a trace in `/` is not supported.");
-        ret = -1;
-        goto end;
+        return -1;
     }
 
     ctf_fs_trace = ctf_fs_trace_create(norm_path->str, trace_name, ctf_fs->clkClsCfg, selfComp,
@@ -786,19 +731,12 @@ static int ctf_fs_component_create_ctf_fs_trace_one_path(struct ctf_fs_component
     if (!ctf_fs_trace) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Cannot create trace for `{}`.",
                                      norm_path->str);
-        goto error;
+        return -1;
     }
 
     traces.emplace_back(std::move(ctf_fs_trace));
 
-    ret = 0;
-    goto end;
-
-error:
-    ret = -1;
-
-end:
-    return ret;
+    return 0;
 }
 
 /*
@@ -847,7 +785,6 @@ static int merge_matching_ctf_fs_ds_file_groups(struct ctf_fs_trace *dest_trace,
 {
     std::vector<ctf_fs_ds_file_group::UP>& dest = dest_trace->ds_file_groups;
     std::vector<ctf_fs_ds_file_group::UP>& src = src_trace->ds_file_groups;
-    int ret = 0;
 
     /*
      * Save the initial length of dest: we only want to check against the
@@ -902,8 +839,7 @@ static int merge_matching_ctf_fs_ds_file_groups(struct ctf_fs_trace *dest_trace,
                                                               bt2s::make_unique<ctf_fs_ds_index>());
 
             if (!new_dest_group) {
-                ret = -1;
-                goto end;
+                return -1;
             }
 
             dest_group = new_dest_group.get();
@@ -914,8 +850,7 @@ static int merge_matching_ctf_fs_ds_file_groups(struct ctf_fs_trace *dest_trace,
         merge_ctf_fs_ds_file_groups(dest_group, std::move(src_group));
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 /*
@@ -932,7 +867,6 @@ static int merge_ctf_fs_traces(std::vector<ctf_fs_trace::UP> traces, ctf_fs_trac
     unsigned int winner_count;
     struct ctf_fs_trace *winner;
     guint i, winner_i;
-    int ret = 0;
 
     BT_ASSERT(traces.size() >= 2);
 
@@ -965,9 +899,9 @@ static int merge_ctf_fs_traces(std::vector<ctf_fs_trace::UP> traces, ctf_fs_trac
         }
 
         /* Merge trace's data stream file groups into winner's. */
-        ret = merge_matching_ctf_fs_ds_file_groups(winner, std::move(trace));
+        int ret = merge_matching_ctf_fs_ds_file_groups(winner, std::move(trace));
         if (ret) {
-            goto end;
+            return ret;
         }
     }
 
@@ -976,8 +910,7 @@ static int merge_ctf_fs_traces(std::vector<ctf_fs_trace::UP> traces, ctf_fs_trac
      */
     out_trace = std::move(traces[winner_i]);
 
-end:
-    return ret;
+    return 0;
 }
 
 enum target_event
@@ -994,7 +927,6 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
 {
     enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK;
     ctf_msg_iter_up msg_iter;
-    int ret = 0;
 
     BT_ASSERT(ctf_fs_trace);
     BT_ASSERT(index_entry);
@@ -1004,8 +936,7 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
                                                index_entry->path, ctf_fs_trace->logger);
     if (!ds_file) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file");
-        ret = -1;
-        goto end;
+        return -1;
     }
 
     BT_ASSERT(ctf_fs_trace->metadata);
@@ -1017,8 +948,7 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
         ctf_fs_ds_file_medops, ds_file.get(), NULL, ctf_fs_trace->logger);
     if (!msg_iter) {
         /* ctf_msg_iter_create() logs errors. */
-        ret = -1;
-        goto end;
+        return -1;
     }
 
     /*
@@ -1031,8 +961,7 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     iter_status = ctf_msg_iter_seek(msg_iter.get(), index_entry->offset.bytes());
     if (iter_status) {
         /* ctf_msg_iter_seek() logs errors. */
-        ret = -1;
-        goto end;
+        return -1;
     }
 
     switch (target_event) {
@@ -1052,21 +981,19 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
         bt_common_abort();
     }
     if (iter_status) {
-        ret = -1;
-        goto end;
+        return -1;
     }
 
     /* Convert clock snapshot to timestamp. */
-    ret = bt_util_clock_cycles_to_ns_from_origin(
+    int ret = bt_util_clock_cycles_to_ns_from_origin(
         *cs, default_cc->frequency, default_cc->offset_seconds, default_cc->offset_cycles, ts_ns);
     if (ret) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger,
                                      "Failed to convert clock snapshot to timestamp");
-        goto end;
+        return ret;
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 static int decode_packet_first_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
@@ -1107,8 +1034,6 @@ static int decode_packet_last_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
  */
 static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace)
 {
-    int ret = 0;
-
     for (const auto& ds_file_group : trace->ds_file_groups) {
         struct ctf_clock_class *default_cc;
 
@@ -1148,19 +1073,18 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace)
          * Decode packet to read the timestamp of the last event of the
          * entry.
          */
-        ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
-                                                 &last_entry->timestamp_end,
-                                                 &last_entry->timestamp_end_ns);
+        int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
+                                                     &last_entry->timestamp_end,
+                                                     &last_entry->timestamp_end_ns);
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(
                 trace->logger,
                 "Failed to decode stream's last packet to get its last event's clock snapshot.");
-            goto end;
+            return ret;
         }
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 /*
@@ -1179,8 +1103,6 @@ end:
  */
 static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
 {
-    int ret = 0;
-
     for (const auto& ds_file_group : trace->ds_file_groups) {
         struct ctf_clock_class *default_cc;
         const auto index = ds_file_group->index.get();
@@ -1202,13 +1124,13 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
              * 2. Set the current entry `begin` timestamp to the
              * timestamp of the first event of the current packet.
              */
-            ret = decode_packet_first_event_timestamp(trace, default_cc, curr_entry,
-                                                      &curr_entry->timestamp_begin,
-                                                      &curr_entry->timestamp_begin_ns);
+            int ret = decode_packet_first_event_timestamp(trace, default_cc, curr_entry,
+                                                          &curr_entry->timestamp_begin,
+                                                          &curr_entry->timestamp_begin_ns);
             if (ret) {
                 BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger,
                                              "Failed to decode first event's clock snapshot");
-                goto end;
+                return ret;
             }
 
             /*
@@ -1219,8 +1141,8 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace)
             prev_entry->timestamp_end_ns = curr_entry->timestamp_begin_ns;
         }
     }
-end:
-    return ret;
+
+    return 0;
 }
 
 /*
@@ -1242,8 +1164,6 @@ end:
  */
 static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace)
 {
-    int ret = 0;
-
     for (const auto& ds_file_group : trace->ds_file_groups) {
         struct ctf_clock_class *default_cc;
 
@@ -1265,13 +1185,13 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace)
              * Decode packet to read the timestamp of the
              * last event of the stream file.
              */
-            ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
-                                                     &last_entry->timestamp_end,
-                                                     &last_entry->timestamp_end_ns);
+            int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
+                                                         &last_entry->timestamp_end,
+                                                         &last_entry->timestamp_end_ns);
             if (ret) {
                 BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger,
                                              "Failed to decode last event's clock snapshot");
-                goto end;
+                return ret;
             }
         }
 
@@ -1291,8 +1211,7 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace)
         }
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 /*
@@ -1302,7 +1221,6 @@ end:
  */
 static int extract_tracer_info(struct ctf_fs_trace *trace, struct tracer_info *current_tracer_info)
 {
-    int ret = 0;
     struct ctf_trace_class_env_entry *entry;
 
     /* Clear the current_tracer_info struct */
@@ -1315,7 +1233,7 @@ static int extract_tracer_info(struct ctf_fs_trace *trace, struct tracer_info *c
      */
     entry = ctf_trace_class_borrow_env_entry_by_name(trace->metadata->tc, "tracer_name");
     if (!entry || entry->type != CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR) {
-        goto missing_bare_minimum;
+        return -1;
     }
 
     /* Set tracer name. */
@@ -1323,7 +1241,7 @@ static int extract_tracer_info(struct ctf_fs_trace *trace, struct tracer_info *c
 
     entry = ctf_trace_class_borrow_env_entry_by_name(trace->metadata->tc, "tracer_major");
     if (!entry || entry->type != CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT) {
-        goto missing_bare_minimum;
+        return -1;
     }
 
     /* Set major version number. */
@@ -1331,7 +1249,7 @@ static int extract_tracer_info(struct ctf_fs_trace *trace, struct tracer_info *c
 
     entry = ctf_trace_class_borrow_env_entry_by_name(trace->metadata->tc, "tracer_minor");
     if (!entry || entry->type != CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT) {
-        goto end;
+        return 0;
     }
 
     /* Set minor version number. */
@@ -1348,18 +1266,13 @@ static int extract_tracer_info(struct ctf_fs_trace *trace, struct tracer_info *c
     }
 
     if (!entry || entry->type != CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT) {
-        goto end;
+        return 0;
     }
 
     /* Set patch version number. */
     current_tracer_info->patch = entry->value.i;
 
-    goto end;
-
-missing_bare_minimum:
-    ret = -1;
-end:
-    return ret;
+    return 0;
 }
 
 static bool is_tracer_affected_by_lttng_event_after_packet_bug(struct tracer_info *curr_tracer_info)
@@ -1442,10 +1355,9 @@ static bool is_tracer_affected_by_lttng_crash_quirk(struct tracer_info *curr_tra
  */
 static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace)
 {
-    int ret = 0;
     struct tracer_info current_tracer_info;
 
-    ret = extract_tracer_info(trace, &current_tracer_info);
+    int ret = extract_tracer_info(trace, &current_tracer_info);
     if (ret) {
         /*
          * A trace may not have all the necessary environment
@@ -1454,11 +1366,10 @@ static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace)
          * are needed. Failing to extract these entries is not
          * an error.
          */
-        ret = 0;
         BT_CPPLOGI_STR_SPEC(
             trace->logger,
             "Cannot extract tracer information necessary to compare with buggy versions.");
-        goto end;
+        return 0;
     }
 
     /* Check if the trace may be affected by old tracer bugs. */
@@ -1470,7 +1381,7 @@ static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace)
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger,
                                          "Failed to fix LTTng event-after-packet bug.");
-            goto end;
+            return ret;
         }
         trace->metadata->tc->quirks.lttng_event_after_packet = true;
     }
@@ -1483,7 +1394,7 @@ static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace)
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger,
                                          "Failed to fix barectf event-before-packet bug.");
-            goto end;
+            return ret;
         }
         trace->metadata->tc->quirks.barectf_event_before_packet = true;
     }
@@ -1493,13 +1404,12 @@ static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace)
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger,
                                          "Failed to fix lttng-crash timestamp quirks.");
-            goto end;
+            return ret;
         }
         trace->metadata->tc->quirks.lttng_crash = true;
     }
 
-end:
-    return ret;
+    return 0;
 }
 
 static bool compare_ds_file_groups_by_first_path(const ctf_fs_ds_file_group::UP& ds_file_group_a,
@@ -1519,7 +1429,6 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
                                          const bt_value *trace_name_value,
                                          bt_self_component *selfComp)
 {
-    int ret = 0;
     std::vector<std::string> paths;
     std::vector<ctf_fs_trace::UP> traces;
     const char *trace_name;
@@ -1543,10 +1452,10 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
 
     /* Create a separate ctf_fs_trace object for each path. */
     for (const auto& path : paths) {
-        ret = ctf_fs_component_create_ctf_fs_trace_one_path(ctf_fs, path.c_str(), trace_name,
-                                                            traces, selfComp);
+        int ret = ctf_fs_component_create_ctf_fs_trace_one_path(ctf_fs, path.c_str(), trace_name,
+                                                                traces, selfComp);
         if (ret) {
-            goto end;
+            return ret;
         }
     }
 
@@ -1567,7 +1476,7 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
                     ctf_fs->logger,
                     "Multiple traces given, but a trace does not have a UUID: path={}",
                     this_trace->path);
-                goto error;
+                return -1;
             }
 
             if (bt_uuid_compare(first_trace_uuid, this_trace_uuid) != 0) {
@@ -1583,24 +1492,25 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
                                              "trace-uuid={}, trace-path={}",
                                              first_trace_uuid_str, first_trace->path,
                                              this_trace_uuid_str, this_trace->path);
-                goto error;
+                return -1;
             }
         }
 
-        ret = merge_ctf_fs_traces(std::move(traces), ctf_fs->trace);
+        int ret = merge_ctf_fs_traces(std::move(traces), ctf_fs->trace);
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger,
                                          "Failed to merge traces with the same UUID.");
-            goto error;
+            return ret;
         }
     } else {
         /* Just one trace, it may or may not have a UUID, both are fine. */
         ctf_fs->trace = std::move(traces[0]);
     }
 
-    ret = fix_packet_index_tracer_bugs(ctf_fs->trace.get());
+    int ret = fix_packet_index_tracer_bugs(ctf_fs->trace.get());
     if (ret) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to fix packet index tracer bugs.");
+        return ret;
     }
 
     /*
@@ -1617,13 +1527,8 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
      */
     std::sort(ctf_fs->trace->ds_file_groups.begin(), ctf_fs->trace->ds_file_groups.end(),
               compare_ds_file_groups_by_first_path);
-    goto end;
-
-error:
-    ret = -1;
 
-end:
-    return ret;
+    return 0;
 }
 
 static const std::string&
@@ -1641,8 +1546,6 @@ get_stream_instance_unique_name(struct ctf_fs_ds_file_group *ds_file_group)
 
 static int create_streams_for_trace(struct ctf_fs_trace *ctf_fs_trace)
 {
-    int ret;
-
     for (const auto& ds_file_group : ctf_fs_trace->ds_file_groups) {
         const std::string& name = get_stream_instance_unique_name(ds_file_group.get());
 
@@ -1669,29 +1572,22 @@ static int create_streams_for_trace(struct ctf_fs_trace *ctf_fs_trace)
                                          "Cannot create stream for DS file group: "
                                          "addr={}, stream-name=\"{}\"",
                                          fmt::ptr(ds_file_group), name);
-            goto error;
+            return -1;
         }
 
         ds_file_group->stream = bt2::Stream::Shared::createWithoutRef(stream);
 
-        ret = bt_stream_set_name(ds_file_group->stream->libObjPtr(), name.c_str());
+        int ret = bt_stream_set_name(ds_file_group->stream->libObjPtr(), name.c_str());
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger,
                                          "Cannot set stream's name: "
                                          "addr={}, stream-name=\"{}\"",
                                          fmt::ptr(ds_file_group->stream->libObjPtr()), name);
-            goto error;
+            return ret;
         }
     }
 
-    ret = 0;
-    goto end;
-
-error:
-    ret = -1;
-
-end:
-    return ret;
+    return 0;
 }
 
 static const bt_param_validation_value_descr inputs_elem_descr =
@@ -1714,7 +1610,6 @@ static bt_param_validation_map_value_entry_descr fs_params_entries_descr[] = {
 bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs,
                             const bt_value **trace_name, struct ctf_fs_component *ctf_fs)
 {
-    bool ret;
     const bt_value *value;
     enum bt_param_validation_status validate_value_status;
     gchar *error = NULL;
@@ -1722,8 +1617,8 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs,
     validate_value_status = bt_param_validation_validate(params, fs_params_entries_descr, &error);
     if (validate_value_status != BT_PARAM_VALIDATION_STATUS_OK) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "{}", error);
-        ret = false;
-        goto end;
+        g_free(error);
+        return false;
     }
 
     /* inputs parameter */
@@ -1750,11 +1645,7 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs,
     /* trace-name parameter */
     *trace_name = bt_value_map_borrow_entry_value_const(params, "trace-name");
 
-    ret = true;
-
-end:
-    g_free(error);
-    return ret;
+    return true;
 }
 
 static ctf_fs_component::UP ctf_fs_create(const bt_value *params,
This page took 0.036628 seconds and 4 git commands to generate.