diff --git a/system/trace/trace.c b/system/trace/trace.c index 03796a9f7..4e94d58bd 100644 --- a/system/trace/trace.c +++ b/system/trace/trace.c @@ -485,29 +485,32 @@ static int trace_cmd_switch(int index, int argc, FAR char **argv, /* Parse the setting parameters */ - if (argv[index][0] == '-' || argv[index][0] == '+') + if (index < argc) { - enable = (argv[index][0] == '+'); - if (enable == - ((mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) != 0)) + if (argv[index][0] == '-' || argv[index][0] == '+') { - /* Already set */ + enable = (argv[index][0] == '+'); + if (enable == + ((mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) != 0)) + { + /* Already set */ - return false; + return false; + } + + if (enable) + { + mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH; + } + else + { + mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH; + } + + ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); + + index++; } - - if (enable) - { - mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH; - } - else - { - mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH; - } - - ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); - - index++; } return index; @@ -735,29 +738,32 @@ static int trace_cmd_print(int index, int argc, FAR char **argv, /* Parse the setting parameters */ - if (argv[index][0] == '-' || argv[index][0] == '+') + if (index < argc) { - enable = (argv[index][0] == '+'); - if (enable == - ((mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) != 0)) + if (argv[index][0] == '-' || argv[index][0] == '+') { - /* Already set */ + enable = (argv[index][0] == '+'); + if (enable == + ((mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) != 0)) + { + /* Already set */ - return false; + return false; + } + + if (enable) + { + mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP; + } + else + { + mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP; + } + + ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); + + index++; } - - if (enable) - { - mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP; - } - else - { - mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP; - } - - ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode); - - index++; } return index;