On Fri, May 15, 2020 at 4:14 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote: > [...] > > +static int parse_arg_format(struct tep_print_parse **parse, > > + struct tep_event *event, > > + const char *format, struct tep_print_arg > > **arg) +{ > > + struct tep_print_arg *len_arg = NULL; > > + char print_format[32]; > > + const char *start = format; > > + int ret = 0; > > + int ls = 0; > > + int res; > > + int len; > > + > > + if (*format != '%') > > + return ret; > > + format++; > > + > > + /* %% */ > > + if (*format == '%') > > + return ret; > > The above two checks for '%' isn't needed as it is checked by the > caller. If for some reason that the caller didn't catch it, and we > return here, it would return zero and the calling loop would never > proceed. It's not protecting anything, I would just remove these two > checks. > > > + ret++; > > + > > + for (; *format; format++) { > > + switch (*format) { > > + case '#': > > + /* FIXME: need to handle properly */ > > + break; > > + case 'h': > > + ls--; > > + break; > > + case 'l': > > + ls++; > > + break; > > + case 'L': > > + ls = 2; > > + break; > > + case '.': > > + case 'z': > > + case 'Z': > > + case '0' ... '9': > > + case '-': > > + break; > > + case '*': > > + /* The argument is the length. */ > > + if (!arg) { > > + do_warning_event(event, "no argument match"); > > + event->flags |= TEP_EVENT_FL_FAILED; > > + goto out_failed; > > + } > > Since all cases to exit this loop do the same check, I think we can > move this check before the loop. The old code didn't do this check > properly for %p, but that was a bug in the old code. > We still have to check for a valid argument inside the switch for almost all exit cases, as the '*' case can consume the argument that would be verified before the loop. And there is one exit that does not require a valid argument - the default case. The old code just prints the unknown character, without consuming an argument. > > > + len_arg = *arg; > [...] > -- Steve Thanks, Steve! -- Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center