[PATCH] libtraceevent: Add support for nested ?: conditionals

Steven Rostedt <[email protected]> Mon, 14 Apr 2025 15:35:26 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
From: "Steven Rostedt (Google)" <[email protected]>

It was reported that nested ?: conditionals were broken in libtraceevent.
Specifically, the following did not parse correctly:

	REC->severity == AER_CORRECTABLE ? "Corrected" :
		REC->severity == AER_FATAL ?
		"Fatal" : "Uncorrected, non-fatal",

That was due to the second half of the ':' operator was not being evaluated.

Link: https://lore.kernel.org/all/[email protected]/

Reported-by: Borislav Petkov <[email protected]>
Reported-by: Sargun Dhillon <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
---
 src/event-parse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/event-parse.c b/src/event-parse.c
index ba6e42b..aa16d83 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -2083,6 +2083,16 @@ process_cond(struct tep_event *event, struct tep_print_arg *top, char **tok)
 
 	type = process_arg(event, right, &token);
 
+ againagain:
+	if (type == TEP_EVENT_ERROR)
+		goto out_free;
+
+	/* Handle other operations in the results */
+	if (type == TEP_EVENT_OP) {
+		type = process_op(event, right, &token);
+		goto againagain;
+	}
+
 	top->op.right = arg;
 
 	*tok = token;
-- 
2.47.2