diff mbox series

libtraceevent: Have single quotes represent characters

Message ID 20240415042631.6310d78b@rorschach.local.home (mailing list archive)
State New
Headers show
Series libtraceevent: Have single quotes represent characters | expand

Commit Message

Steven Rostedt April 15, 2024, 8:26 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

In parsing the print fmt parameters, the code currently treats both single
and double quotes the same. But they are not. Double quotes represent
strings and single quotes represent characters.

A character could be used as a number as well, so it needs to be treated
as such.

Link: https://lore.kernel.org/all/20240315174900.14418f22@booty/

Fixes: 6582b0aea1cc ("tools/events: Add files to create libtraceevent.a")
Reported-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/event-parse.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index d607556ea1a9..61b09662f28f 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -3732,8 +3732,19 @@  process_arg_token(struct tep_event *event, struct tep_print_arg *arg,
 		arg->atom.atom = atom;
 		break;
 
-	case TEP_EVENT_DQUOTE:
 	case TEP_EVENT_SQUOTE:
+		arg->type = TEP_PRINT_ATOM;
+		/* Make characters into numbers */
+		if (asprintf(&arg->atom.atom, "%d", token[0]) < 0) {
+			free_token(token);
+			*tok = NULL;
+			arg->atom.atom = NULL;
+			return TEP_EVENT_ERROR;
+		}
+		free_token(token);
+		type = read_token_item(event->tep, &token);
+		break;
+	case TEP_EVENT_DQUOTE:
 		arg->type = TEP_PRINT_ATOM;
 		arg->atom.atom = token;
 		type = read_token_item(event->tep, &token);