From a6d50870e2a6b6bf14300ebe33b2a467b7dea6ad Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Dec 2023 05:50:32 +0000 Subject: [PATCH] src.ctf.fs: use std::string in build_index_from_idx_file Change-Id: Ifdb2c818f66efbc328b095408ae2834646fba4fe Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8310 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12337 Tested-by: jenkins --- src/plugins/ctf/fs-src/data-stream-file.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 3a512496..77305a38 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -448,7 +448,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f int ret; bt2c::GCharUP directory; bt2c::GCharUP basename; - GString *index_basename = NULL; + std::string index_basename; bt2c::GCharUP index_file_path; GMappedFile *mapped_file = NULL; gsize filesize; @@ -496,14 +496,8 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f goto error; } - index_basename = g_string_new(basename.get()); - if (!index_basename) { - BT_CPPLOGE_STR_SPEC(ds_file->logger, "Cannot allocate index file basename string"); - goto error; - } - - g_string_append(index_basename, ".idx"); - index_file_path.reset(g_build_filename(directory.get(), "index", index_basename->str, NULL)); + index_basename = fmt::format("{}.idx", basename.get()); + index_file_path.reset(g_build_filename(directory.get(), "index", index_basename.c_str(), NULL)); mapped_file = g_mapped_file_new(index_file_path.get(), FALSE, NULL); if (!mapped_file) { BT_CPPLOGD_SPEC(ds_file->logger, "Cannot create new mapped file {}", index_file_path.get()); @@ -645,9 +639,6 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f goto error; } end: - if (index_basename) { - g_string_free(index_basename, TRUE); - } if (mapped_file) { g_mapped_file_unref(mapped_file); } -- 2.34.1