Linux Trace Development
 help / color / mirror / Atom feed
* [PATCH] libtraceevent: Have single quotes represent characters
@ 2024-04-15  8:26 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2024-04-15  8:26 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Luca Ceresoli

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 --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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-15  8:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15  8:26 [PATCH] libtraceevent: Have single quotes represent characters Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox