From b7e4a53ce230f0118d5b45206f8c4f0319f4d377 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 4 Sep 2020 16:05:37 -0700 Subject: [PATCH] backend: Use asprintf() instead of strlen() + sprintf() This patch does not change any functionality but makes exec_string() easier to read. Signed-off-by: Bart Van Assche --- backend.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend.c b/backend.c index c7a027e7..f91f3caf 100644 --- a/backend.c +++ b/backend.c @@ -1458,16 +1458,17 @@ static bool keep_running(struct thread_data *td) return false; } -static int exec_string(struct thread_options *o, const char *string, const char *mode) +static int exec_string(struct thread_options *o, const char *string, + const char *mode) { - size_t newlen = strlen(string) + strlen(o->name) + strlen(mode) + 13 + 1; int ret; char *str; - str = malloc(newlen); - sprintf(str, "%s > %s.%s.txt 2>&1", string, o->name, mode); + if (asprintf(&str, "%s > %s.%s.txt 2>&1", string, o->name, mode) < 0) + return -1; - log_info("%s : Saving output of %s in %s.%s.txt\n",o->name, mode, o->name, mode); + log_info("%s : Saving output of %s in %s.%s.txt\n", o->name, mode, + o->name, mode); ret = system(str); if (ret == -1) log_err("fio: exec of cmd <%s> failed\n", str); -- 2.25.1