Fix: negative loop bound check
[babeltrace.git] / cli / babeltrace-cfg-cli-args.c
index e4d66b7ffcf7eaa0e8fb6b171dadbdedc972f08b..2978ab48a03f43ef3f539a0e14787cc6fae09b2c 100644 (file)
@@ -2719,7 +2719,7 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args,
 {
        struct bt_config *cfg = NULL;
        const char **argv;
-       size_t i;
+       int64_t i, len;
        const size_t argc = bt_value_array_size(run_args) + 1;
 
        argv = calloc(argc, sizeof(*argv));
@@ -2730,7 +2730,12 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args,
 
        argv[0] = "run";
 
-       for (i = 0; i < bt_value_array_size(run_args); i++) {
+       len = bt_value_array_size(run_args);
+       if (len < 0) {
+               printf_err("Invalid executable arguments\n");
+               goto end;
+       }
+       for (i = 0; i < len; i++) {
                int ret;
                struct bt_value *arg_value = bt_value_array_get(run_args, i);
                const char *arg;
@@ -3596,6 +3601,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        bool got_output_format_opt = false;
        bool trimmer_has_begin = false;
        bool trimmer_has_end = false;
+       bool stream_intersection_mode = false;
        GString *cur_name = NULL;
        GString *cur_name_prefix = NULL;
        const char *leftover = NULL;
@@ -4106,20 +4112,14 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                case OPT_CLOCK_OFFSET:
                        base_implicit_ctf_input_args.exists = true;
                        append_implicit_component_param(
-                                       &implicit_muxer_args,
+                                       &base_implicit_ctf_input_args,
                                        "clock-class-offset-s", arg);
-                       if (ret) {
-                               goto error;
-                       }
                        break;
                case OPT_CLOCK_OFFSET_NS:
                        base_implicit_ctf_input_args.exists = true;
-                       ret = append_implicit_component_extra_param(
-                               &base_implicit_ctf_input_args,
-                               "clock-class-offset-ns", arg);
-                       if (ret) {
-                               goto error;
-                       }
+                       append_implicit_component_param(
+                                       &base_implicit_ctf_input_args,
+                                       "clock-class-offset-ns", arg);
                        break;
                case OPT_CLOCK_SECONDS:
                        append_implicit_component_param(
@@ -4269,10 +4269,11 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        print_run_args_0 = true;
                        break;
                case OPT_STREAM_INTERSECTION:
-                       append_implicit_component_param(
-                               &base_implicit_ctf_input_args,
-                               "stream-intersection", "yes");
-                       base_implicit_ctf_input_args.exists = true;
+                       /*
+                        * Applies to all traces implementing the trace-info
+                        * query.
+                        */
+                       stream_intersection_mode = true;
                        break;
                case OPT_VERBOSE:
                        if (*log_level != 'V' && *log_level != 'D') {
@@ -4658,6 +4659,11 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
         * here.
         */
        if (print_run_args || print_run_args_0) {
+               if (stream_intersection_mode) {
+                       printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
+                       goto error;
+               }
+
                for (i = 0; i < bt_value_array_size(run_args); i++) {
                        struct bt_value *arg_value =
                                bt_value_array_get(run_args, i);
@@ -4708,6 +4714,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                goto error;
        }
 
+       cfg->cmd_data.run.stream_intersection_mode = stream_intersection_mode;
        goto end;
 
 error:
This page took 0.026888 seconds and 4 git commands to generate.