From: Jérémie Galarneau Date: Fri, 4 Mar 2016 16:31:00 +0000 (-0500) Subject: Optimization: lttng UI uses sprintf instead of strcpy X-Git-Tag: v2.8.0-rc1~121 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=19ed763285b27e717bbc7835b31098629682dd1f;p=lttng-tools.git Optimization: lttng UI uses sprintf instead of strcpy The LTTng client currently uses sprintf with format strings that don't contain a format specifier. Users have reported concerns for the scalability and performance of the LTTng UI because of this overkill use of sprintf instead of strcpy which, presumably, could be inlined by the compiler. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index efa1abfd0..bcada31cd 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -214,6 +214,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event) int count; size_t i; const char * const exclusion_fmt = " [exclusions: "; + const size_t exclusion_fmt_len = strlen(exclusion_fmt); exclusion_count = lttng_event_get_exclusion_name_count(event); if (exclusion_count < 0) { @@ -234,15 +235,12 @@ static char *get_exclusion_names_msg(struct lttng_event *event) */ exclusion_msg = malloc(exclusion_count + exclusion_count * LTTNG_SYMBOL_NAME_LEN + - strlen(exclusion_fmt) + 1); + exclusion_fmt_len + 1); if (!exclusion_msg) { goto end; } - at = exclusion_msg; - count = sprintf(at, exclusion_fmt); - at += count; - + at = strcpy(exclusion_msg, exclusion_fmt) + exclusion_fmt_len; for (i = 0; i < exclusion_count; ++i) { const char *name; @@ -266,7 +264,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event) } /* This also puts a final '\0' at the end of exclusion_msg */ - sprintf(at, "]"); + strcpy(at, "]"); end: return exclusion_msg;