fix: bt_put on potentially unintialized variable
[babeltrace.git] / plugins / libctfcopytrace / ctfcopytrace.c
index 898e6c4ef2828d4f863fbff728dda9d82128b319..99a332bebce9e8c3c6227c6599e12d08a6ca249e 100644 (file)
@@ -39,6 +39,7 @@
 #include "ctfcopytrace.h"
 #include "clock-fields.h"
 
+BT_HIDDEN
 struct bt_ctf_clock_class *ctf_copy_clock_class(FILE *err,
                struct bt_ctf_clock_class *clock_class)
 {
@@ -156,6 +157,7 @@ end:
        return writer_clock_class;
 }
 
+BT_HIDDEN
 enum bt_component_status ctf_copy_clock_classes(FILE *err,
                struct bt_ctf_trace *writer_trace,
                struct bt_ctf_stream_class *writer_stream_class,
@@ -169,7 +171,7 @@ enum bt_component_status ctf_copy_clock_classes(FILE *err,
        for (i = 0; i < clock_class_count; i++) {
                struct bt_ctf_clock_class *writer_clock_class;
                struct bt_ctf_clock_class *clock_class =
-                       bt_ctf_trace_get_clock_class(trace, i);
+                       bt_ctf_trace_get_clock_class_by_index(trace, i);
 
                if (!clock_class) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
@@ -207,6 +209,7 @@ end:
        return ret;
 }
 
+BT_HIDDEN
 struct bt_ctf_event_class *ctf_copy_event_class(FILE *err,
                struct bt_ctf_event_class *event_class)
 {
@@ -234,13 +237,15 @@ struct bt_ctf_event_class *ctf_copy_event_class(FILE *err,
                struct bt_value *attr_value;
                int ret;
 
-               attr_name = bt_ctf_event_class_get_attribute_name(event_class, i);
+               attr_name = bt_ctf_event_class_get_attribute_name_by_index(
+                       event_class, i);
                if (!attr_name) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
                                        __FILE__, __LINE__);
                        goto error;
                }
-               attr_value = bt_ctf_event_class_get_attribute_value(event_class, i);
+               attr_value = bt_ctf_event_class_get_attribute_value_by_index(
+                       event_class, i);
                if (!attr_value) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
                                        __FILE__, __LINE__);
@@ -257,14 +262,14 @@ struct bt_ctf_event_class *ctf_copy_event_class(FILE *err,
                }
        }
 
-       count = bt_ctf_event_class_get_field_count(event_class);
+       count = bt_ctf_event_class_get_payload_type_field_count(event_class);
        for (i = 0; i < count; i++) {
                const char *field_name;
                struct bt_ctf_field_type *field_type;
                int ret;
 
-               ret = bt_ctf_event_class_get_field(event_class, &field_name,
-                               &field_type, i);
+               ret = bt_ctf_event_class_get_payload_type_field_by_index(
+                               event_class, &field_name, &field_type, i);
                if (ret < 0) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
                        goto error;
@@ -288,6 +293,7 @@ end:
        return writer_event_class;
 }
 
+BT_HIDDEN
 enum bt_component_status ctf_copy_event_classes(FILE *err,
                struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_stream_class *writer_stream_class)
@@ -307,7 +313,7 @@ enum bt_component_status ctf_copy_event_classes(FILE *err,
                struct bt_ctf_field_type *context;
                int int_ret;
 
-               event_class = bt_ctf_stream_class_get_event_class(
+               event_class = bt_ctf_stream_class_get_event_class_by_index(
                                stream_class, i);
                if (!event_class) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
@@ -360,6 +366,7 @@ end:
        return ret;
 }
 
+BT_HIDDEN
 struct bt_ctf_stream_class *ctf_copy_stream_class(FILE *err,
                struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_trace *writer_trace,
@@ -454,6 +461,7 @@ end:
        return writer_stream_class;
 }
 
+BT_HIDDEN
 enum bt_component_status ctf_copy_packet_context_field(FILE *err,
                struct bt_ctf_field *field, const char *field_name,
                struct bt_ctf_field *writer_packet_context,
@@ -482,8 +490,8 @@ enum bt_component_status ctf_copy_packet_context_field(FILE *err,
        }
        BT_PUT(field_type);
 
-       writer_field = bt_ctf_field_structure_get_field(writer_packet_context,
-                       field_name);
+       writer_field = bt_ctf_field_structure_get_field_by_name(
+               writer_packet_context, field_name);
        if (!writer_field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
@@ -519,23 +527,23 @@ end:
        return ret;
 }
 
+BT_HIDDEN
 struct bt_ctf_field *ctf_copy_packet_context(FILE *err,
                struct bt_ctf_packet *packet,
-               struct bt_ctf_stream *writer_stream)
+               struct bt_ctf_stream *writer_stream,
+               int skip_content_size)
 {
        enum bt_component_status ret;
        struct bt_ctf_field *packet_context = NULL, *writer_packet_context = NULL;
        struct bt_ctf_field_type *struct_type = NULL, *writer_packet_context_type = NULL;
        struct bt_ctf_stream_class *writer_stream_class = NULL;
        struct bt_ctf_field *field = NULL;
-       struct bt_ctf_field_type *field_type;
+       struct bt_ctf_field_type *field_type = NULL;
        int nr_fields, i;
 
        packet_context = bt_ctf_packet_get_context(packet);
        if (!packet_context) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
-                               __LINE__);
-               goto error;
+               goto end;
        }
 
        writer_stream_class = bt_ctf_stream_get_class(writer_stream);
@@ -579,15 +587,15 @@ struct bt_ctf_field *ctf_copy_packet_context(FILE *err,
                                        __FILE__, __LINE__);
                        goto error;
                }
-               if (bt_ctf_field_type_structure_get_field(struct_type,
+               if (bt_ctf_field_type_structure_get_field_by_index(struct_type,
                                        &field_name, &field_type, i) < 0) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
                                        __FILE__, __LINE__);
                        goto error;
                }
-               if (!strncmp(field_name, "content_size", strlen("content_size")) ||
-                               !strncmp(field_name, "packet_size",
-                                       strlen("packet_size"))) {
+               if (skip_content_size &&
+                               (!strncmp(field_name, "content_size", strlen("content_size")) ||
+                               !strncmp(field_name, "packet_size", strlen("packet_size")))) {
                        BT_PUT(field_type);
                        BT_PUT(field);
                        continue;
@@ -623,6 +631,7 @@ end:
        return writer_packet_context;
 }
 
+BT_HIDDEN
 int ctf_copy_event_header(FILE *err, struct bt_ctf_event *event,
                struct bt_ctf_event_class *writer_event_class,
                struct bt_ctf_event *writer_event,
@@ -706,6 +715,7 @@ end:
        return ret;
 }
 
+BT_HIDDEN
 struct bt_ctf_event *ctf_copy_event(FILE *err, struct bt_ctf_event *event,
                struct bt_ctf_event_class *writer_event_class,
                bool override_ts64)
@@ -788,7 +798,7 @@ struct bt_ctf_event *ctf_copy_event(FILE *err, struct bt_ctf_event *event,
        BT_PUT(field);
        BT_PUT(copy_field);
 
-       field = bt_ctf_event_get_payload_field(event);
+       field = bt_ctf_event_get_event_payload(event);
        if (!field) {
                fprintf(err, "[error] %s in %s:%d\n", __func__,
                                __FILE__, __LINE__);
@@ -796,7 +806,7 @@ struct bt_ctf_event *ctf_copy_event(FILE *err, struct bt_ctf_event *event,
        }
        copy_field = bt_ctf_field_copy(field);
        if (copy_field) {
-               ret = bt_ctf_event_set_payload_field(writer_event, copy_field);
+               ret = bt_ctf_event_set_event_payload(writer_event, copy_field);
                if (ret < 0) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
                                        __FILE__, __LINE__);
@@ -816,12 +826,14 @@ end:
        return writer_event;
 }
 
+BT_HIDDEN
 enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace,
                struct bt_ctf_trace *writer_trace)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        int field_count, i, int_ret;
        struct bt_ctf_field_type *header_type = NULL;
+       enum bt_ctf_byte_order order;
 
        field_count = bt_ctf_trace_get_environment_field_count(trace);
        for (i = 0; i < field_count; i++) {
@@ -829,14 +841,16 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace,
                const char *name;
                struct bt_value *value = NULL;
 
-               name = bt_ctf_trace_get_environment_field_name(trace, i);
+               name = bt_ctf_trace_get_environment_field_name_by_index(
+                       trace, i);
                if (!name) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                        __LINE__);
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
-               value = bt_ctf_trace_get_environment_field_value(trace, i);
+               value = bt_ctf_trace_get_environment_field_value_by_index(
+                       trace, i);
                if (!value) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                        __LINE__);
@@ -857,6 +871,20 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace,
                }
        }
 
+       order = bt_ctf_trace_get_native_byte_order(trace);
+       if (order == BT_CTF_BYTE_ORDER_UNKNOWN) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
+       ret = bt_ctf_trace_set_native_byte_order(writer_trace, order);
+       if (ret) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
        header_type = bt_ctf_trace_get_packet_header_type(writer_trace);
        if (!header_type) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
This page took 0.027141 seconds and 4 git commands to generate.