[PATCH 2/2] perf tools: Fix parsing of unary operator in ?: expression

From: JÃrg Sommer
Date: Sun Mar 25 2012 - 17:12:31 EST


Parsing an expression like

print fmt: "reason %s (%d)", â, REC->errno < 0 ? -REC->errno : REC->reason

in kvm_space_exit fails with

Fatal unknown op ':'

The colon after a simple operator signals the end of this expression. The
token should not be advanced, because the colon is handled in
process_cond(). Hence, it's enough to signal there's an operation
heading.

Signed-off-by: JÃrg Sommer <joerg@xxxxxxxxxxxx>
---
An alternative could be:

--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -1287,7 +1287,7 @@ process_op(struct event *event, struct print_arg *arg, char **tok)
return EVENT_NONE;
}

- if (type == EVENT_OP) {
+ if (type == EVENT_OP && strcmp(*tok, ":") != 0) {
int prio;

/* higher prios need to be closer to the root */


tools/perf/util/trace-event-parse.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 185e284..d7b5880 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -1125,6 +1125,7 @@ static int get_op_prio(char *op)
case '|':
return 13;
case '?':
+ case ':':
return 16;
default:
die("unknown op '%c'", op[0]);
@@ -1202,6 +1203,8 @@ process_op(struct event *event, struct print_arg *arg, char **tok)

type = process_arg(event, right, tok);

+ } else if (strcmp(token, ":") == 0) {
+ return EVENT_OP;
} else if (strcmp(token, "?") == 0) {

left = malloc_or_die(sizeof(*left));
--
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/