Skip to contentSkip to conversation

libtraceevent: Fix bug in tep_print_event()

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 5 messages Jun 30, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceevent: Fix bug in tep_print_event()

We must handle the case when the "tep_event" object is not found.

---
 src/event-parse.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
src/event-parse.c +8 -4
index de28b3b..d3f1bba 100644
@@ -6418,17 +6418,21 @@ void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
 		     struct tep_record *record, const char *fmt, ...)
 {
 	struct print_event_type type;
-	char *format = strdup(fmt);
-	char *current = format;
-	char *str = format;
+	char *format, *current, *str;
 	int offset;
 	va_list args;
 	struct tep_event *event;
 
+	event = tep_find_event_by_record(tep, record);
+	if (!event) {
+		trace_seq_printf(s, "[UNKNOWN EVENT]");
+		return;
+	}
+
+	str = current = format = strdup(fmt);
 	if (!format)
 		return;
 
-	event = tep_find_event_by_record(tep, record);
 	va_start(args, fmt);
 	while (*current) {
 		current = strchr(str, '%');
Signature · 1 line
2.27.0
#1 lore raw

src/event-parse.c void tep_print_event(struct tep_handle *tep, struct trace_seq *s, · line 6421

Quoted 6 lines · On Wed, 30 Jun 2021 17:19:13 +0300 "Yordan Karadzhov (VMware)"…

{

src/event-parse.c +1 -3
 	struct print_event_type type;
-	char *format = strdup(fmt);
-	char *current = format;
-	char *str = format;
+	char *format, *current, *str;

Nit, but please keep the above each on a separate line.

	char *current;
	char *format;
	char *str;

I try to avoid having pointers on a single line, it's just easier to manage when they are separate.

Thanks!

-- Steve

Quoted 13 lines
src/event-parse.c +7 -0
 	int offset;
 	va_list args;
 	struct tep_event *event;
 
+	event = tep_find_event_by_record(tep, record);
+	if (!event) {
+		trace_seq_printf(s, "[UNKNOWN EVENT]");
+		return;
+	}
+
+	str = current = format = strdup(fmt);
 	if (!format)
 		return;
#2 lore raw
Quoted 12 lines · Steven Rostedt

src/event-parse.c void tep_print_event(struct tep_handle *tep, struct trace_seq *s, · line 6421

Quoted 6 lines · On Wed, 30 Jun 2021 17:19:13 +0300 "Yordan Karadzhov (VMware)"…

{
struct print_event_type type;

src/event-parse.c +1 -3
-	char *format = strdup(fmt);
-	char *current = format;
-	char *str = format;
+	char *format, *current, *str;

Nit, but please keep the above each on a separate line.

Quoted 6 lines
	char *current;
	char *format;
	char *str;

I try to avoid having pointers on a single line, it's just easier to manage when they are separate.

I am sorry!
I somehow forgot that we already discussed this before. Should I send v2?

Thanks,
Y.

Quoted 18 lines

Thanks!

-- Steve

Quoted 13 lines

int offset;
va_list args;
struct tep_event *event;

src/event-parse.c +7 -0
+	event = tep_find_event_by_record(tep, record);
+	if (!event) {
+		trace_seq_printf(s, "[UNKNOWN EVENT]");
+		return;
+	}
+
+	str = current = format = strdup(fmt);
  	if (!format)
  		return;
#3 lore raw
Quoted 17 lines · On Wed, 30 Jun 2021 21:37:48 +0300 "Yordan Karadzhov (VMware)"…
Quoted 16 lines · Steven Rostedt

src/event-parse.c void tep_print_event(struct tep_handle *tep, struct trace_seq *s, · line 6421

Quoted 6 lines · On Wed, 30 Jun 2021 17:19:13 +0300 "Yordan Karadzhov (VMware)"…

{
struct print_event_type type;

src/event-parse.c +1 -3
-	char *format = strdup(fmt);
-	char *current = format;
-	char *str = format;
+	char *format, *current, *str;  

Nit, but please keep the above each on a separate line.

	char *current;
	char *format;
	char *str;
Quoted 7 lines
Quoted 2 lines

I try to avoid having pointers on a single line, it's just easier to manage when they are separate.

I am sorry!
I somehow forgot that we already discussed this before. Should I send v2?

Yeah, if it's not too much of a hassle.

Thanks,

-- Steve

#4 lore raw
Quoted 3 lines · Steven Rostedt
Quoted 2 lines

Should I send v2?

Yeah, if it's not too much of a hassle.

Done.

Thanks!
Y.