Fix: ctf: set `ret` on error paths
[babeltrace.git] / src / plugins / ctf / common / metadata / visitor-generate-ir.c
index 22379aa9d4ee3cc1f4a2cb232684bdd5f51a5f59..a7ea0f0978f87cae6316560a3b026a8f936c88a0 100644 (file)
@@ -1,30 +1,10 @@
 /*
- * ctf-visitor-generate-ir.c
+ * SPDX-License-Identifier: MIT
  *
- * Common Trace Format metadata visitor (generates CTF IR objects).
- *
- * Based on older ctf-visitor-generate-io-struct.c.
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright 2015-2018 - Philippe Proulx <philippe.proulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2015-2018 Philippe Proulx <philippe.proulx@efficios.com>
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Common Trace Format metadata visitor (generates CTF IR objects).
  */
 
 #define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp)
@@ -49,7 +29,6 @@
 
 #include "logging.h"
 #include "scanner.h"
-#include "parser.h"
 #include "ast.h"
 #include "decoder.h"
 #include "ctf-meta.h"
@@ -869,6 +848,7 @@ end:
        return ret;
 }
 
+static
 int get_unary_uuid(struct ctx *ctx, struct bt_list_head *head,
                bt_uuid_t uuid)
 {
@@ -3494,6 +3474,8 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx,
                } else if (root_fc->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
                        named_fc = ctf_field_class_variant_borrow_option_by_index(
                                var_fc, i);
+               } else {
+                       bt_common_abort();
                }
 
                if (strcmp(named_fc->name->str, field_name) == 0) {
@@ -3739,6 +3721,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
                        _BT_COMP_LOGE_NODE(node,
                                "Stream class has a `id` attribute, "
                                "but trace has no packet header field class.");
+                       ret = -EINVAL;
                        goto error;
                }
 
@@ -3748,6 +3731,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
                        _BT_COMP_LOGE_NODE(node,
                                "Stream class has a `id` attribute, "
                                "but trace's packet header field class has no `stream_id` field.");
+                       ret = -EINVAL;
                        goto error;
                }
 
@@ -3756,6 +3740,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
                        _BT_COMP_LOGE_NODE(node,
                                "Stream class has a `id` attribute, "
                                "but trace's packet header field class's `stream_id` field is not an integer field class.");
+                       ret = -EINVAL;
                        goto error;
                }
        } else {
@@ -3850,6 +3835,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        if (val != 1) {
                                _BT_COMP_LOGE_NODE(node,
                                        "Invalid trace's `minor` attribute: expecting 1.");
+                               ret = -EINVAL;
                                goto error;
                        }
 
@@ -3874,6 +3860,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        if (val != 8) {
                                _BT_COMP_LOGE_NODE(node,
                                        "Invalid trace's `minor` attribute: expecting 8.");
+                               ret = -EINVAL;
                                goto error;
                        }
 
@@ -4674,7 +4661,7 @@ bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
 {
        struct ctx *ctx = (void *) visitor;
 
-       BT_ASSERT(ctx);
+       BT_ASSERT_DBG(ctx);
 
        if (ctx->trace_class) {
                bt_trace_class_get_ref(ctx->trace_class);
@@ -4689,8 +4676,8 @@ struct ctf_trace_class *ctf_visitor_generate_ir_borrow_ctf_trace_class(
 {
        struct ctx *ctx = (void *) visitor;
 
-       BT_ASSERT(ctx);
-       BT_ASSERT(ctx->ctf_tc);
+       BT_ASSERT_DBG(ctx);
+       BT_ASSERT_DBG(ctx->ctf_tc);
        return ctx->ctf_tc;
 }
 
@@ -4885,6 +4872,13 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                goto end;
        }
 
+       /* Update structure/array/sequence alignments */
+       ret = ctf_trace_class_update_alignments(ctx->ctf_tc);
+       if (ret) {
+               ret = -EINVAL;
+               goto end;
+       }
+
        /* Resolve sequence lengths and variant tags */
        ret = ctf_trace_class_resolve_field_classes(ctx->ctf_tc, &ctx->log_cfg);
        if (ret) {
This page took 0.024947 seconds and 4 git commands to generate.