Skip to contentSkip to conversation

libtraceevent: Avoid a simple asprintf case

PATCH In review Ian Rogers 2 participants 5 messages May 9, 2024 – May 28, 2024

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 libtraceevent: Avoid a simple asprintf case

Avoid an asprintf for the single character TEP_EVENT_NEWLINE and TEP_EVENT_DELIM case.

---
 src/event-parse.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/event-parse.c +4 -2
index b6ae67e..16fdb46 100644
@@ -1232,9 +1232,11 @@ static enum tep_event_type __read_token(struct tep_handle *tep, char **tok)
 	switch (type) {
 	case TEP_EVENT_NEWLINE:
 	case TEP_EVENT_DELIM:
-		if (asprintf(tok, "%c", ch) < 0)
+		*tok = malloc(2);
+		if (!*tok)
 			return TEP_EVENT_ERROR;
-
+		(*tok)[0] = ch;
+		(*tok)[1] = '\0';
 		return type;
 
 	case TEP_EVENT_OP:
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
#1 lore raw
Quoted 2 lines · On Wed, 8 May 2024 22:13:17 -0700 Ian Rogers <[email protected]> wrote:

Avoid an asprintf for the single character TEP_EVENT_NEWLINE and TEP_EVENT_DELIM case.

This states what the patch does, but omits why. What's wrong with asprintf() here?

-- Steve

author
#2 lore raw
Quoted 9 lines · Steven Rostedt
Quoted 2 lines · On Wed, 8 May 2024 22:13:17 -0700 Ian Rogers <[email protected]> wrote:

Avoid an asprintf for the single character TEP_EVENT_NEWLINE and TEP_EVENT_DELIM case.

This states what the patch does, but omits why. What's wrong with asprintf() here?

Nothing except overhead. I was tracking down an asprintf issue [1], asprintf breaking the sanitizer stack traces on my debian based linux, and using asprintf for the sake of copying a character was creating a huge amount of noise for me. 2 lines-of-code extra means this change is by one measure more complex but it removes special knowledge of asprintf return values and the meaning of %c, so on the other hand it is less complex. I won't be offended if it's not accepted.

Thanks,
Ian

[1] https://lore.kernel.org/lkml/[email protected]/

Quoted 1 line

-- Steve

#3 lore raw
Quoted 10 lines · On Thu, 16 May 2024 15:09:40 -0700 Ian Rogers <[email protected]> wrote:
Quoted 2 lines

This states what the patch does, but omits why. What's wrong with asprintf() here?

Nothing except overhead. I was tracking down an asprintf issue [1], asprintf breaking the sanitizer stack traces on my debian based linux, and using asprintf for the sake of copying a character was creating a huge amount of noise for me. 2 lines-of-code extra means this change is by one measure more complex but it removes special knowledge of asprintf return values and the meaning of %c, so on the other hand it is less complex. I won't be offended if it's not accepted.

I don't mind taking the patch, but the above description is needed in the change log, as that explains the purpose of the patch.

You don't need to resend, I'll just cut and paste what you wrote above to the commit message.

Thanks,

-- Steve

author
#4 lore raw
Quoted 15 lines · Steven Rostedt
Quoted 10 lines · On Thu, 16 May 2024 15:09:40 -0700 Ian Rogers <[email protected]> wrote:
Quoted 2 lines

This states what the patch does, but omits why. What's wrong with asprintf() here?

Nothing except overhead. I was tracking down an asprintf issue [1], asprintf breaking the sanitizer stack traces on my debian based linux, and using asprintf for the sake of copying a character was creating a huge amount of noise for me. 2 lines-of-code extra means this change is by one measure more complex but it removes special knowledge of asprintf return values and the meaning of %c, so on the other hand it is less complex. I won't be offended if it's not accepted.

Quoted 5 lines

I don't mind taking the patch, but the above description is needed in the change log, as that explains the purpose of the patch.

You don't need to resend, I'll just cut and paste what you wrote above to the commit message.

Thanks, the commit message LGTM.

Ian

Quoted 3 lines

Thanks,

-- Steve