Fix: use of uninitialized value in visit_*_decl_entry
[babeltrace.git] / plugins / ctf / common / metadata / visitor-generate-ir.c
index 07f4391fcbcb0c2bf8b1e2fbab2490c14be288f5..badbf995bacaecbd99a97857a252372ca706cad3 100644 (file)
@@ -1173,7 +1173,7 @@ static
 int get_type_specifier_list_name(struct ctx *ctx,
        struct ctf_node *type_specifier_list, GString *str)
 {
-       int ret;
+       int ret = 0;
        struct ctf_node *iter;
        int alias_item_nr = 0;
        struct bt_list_head *head =
@@ -3037,7 +3037,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
 
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                (uint64_t *) &id);
-                       if (ret || id < 0) {
+                       /* Only read "id" if get_unary_unsigned() succeeded. */
+                       if (ret || (!ret && id < 0)) {
                                _PERROR("%s", "unexpected unary expression for event declaration's \"id\" attribute");
                                ret = -EINVAL;
                                goto error;
@@ -3061,7 +3062,11 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
 
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                (uint64_t *) stream_id);
-                       if (ret || *stream_id < 0) {
+                       /*
+                        * Only read "stream_id" if get_unary_unsigned()
+                        * succeeded.
+                        */
+                       if (ret || (!ret && *stream_id < 0)) {
                                _PERROR("%s", "unexpected unary expression for event declaration's \"stream_id\" attribute");
                                ret = -EINVAL;
                                goto error;
@@ -3575,7 +3580,8 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
 
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                (uint64_t *) &id);
-                       if (ret || id < 0) {
+                       /* Only read "id" if get_unary_unsigned() succeeded. */
+                       if (ret || (!ret && id < 0)) {
                                _PERROR("%s", "unexpected unary expression for stream declaration's \"id\" attribute");
                                ret = -EINVAL;
                                goto error;
This page took 0.023494 seconds and 4 git commands to generate.