Re: [PATCH 1/2] perf tools: Concatenate strings in expressions

From: Arnaldo Carvalho de Melo
Date: Mon Mar 26 2012 - 14:15:26 EST


Em Sun, Mar 25, 2012 at 11:08:39PM +0200, JÃrg Sommer escreveu:
> The tracepoint event kvm_userspace_exit uses string snippet the C
> compiler concatenates to a big string, e.g. "KVM_EXIT_" "UNKNOWN". The
> parser of the data must do the same and join successive strings.
>
> print fmt: "reason %s (%d)", â __print_symbolic(REC->reason, { 0, "KVM_EXIT_" "UNKNOWN" }, { 1, "KVM_EXIT_" "EXCEPTION" } â
>
> Signed-off-by: JÃrg Sommer <joerg@xxxxxxxxxxxx>
> ---
> tools/perf/util/trace-event-parse.c | 15 +++++++++++++++
> 1 files changed, 15 insertions(+), 0 deletions(-)
>
> diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
> index 1a8d4dc..185e284 100644
> --- a/tools/perf/util/trace-event-parse.c
> +++ b/tools/perf/util/trace-event-parse.c
> @@ -1726,6 +1726,21 @@ process_arg_token(struct event *event, struct print_arg *arg,
> }
> break;
> case EVENT_DQUOTE:
> + atom = token;
> + type = read_token_item(&token);
> +
> + /* merge with following strings */
> + while (type == EVENT_DQUOTE) {
> + atom = realloc(atom, strlen(atom) + strlen(token) + 1);

realloc can fail, please check its result and take appropriate action.

- Arnaldo

> + strcat(atom, token);
> + free_token(token);
> + type = read_token_item(&token);
> + }
> +
> + arg->type = PRINT_ATOM;
> + arg->atom.atom = atom;
> +
> + break;
> case EVENT_SQUOTE:
> arg->type = PRINT_ATOM;
> arg->atom.atom = token;
> --
> 1.7.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/