From 0c04e31405175387bc321c996b1ab263a7abff2d Mon Sep 17 00:00:00 2001 From: Pengfei Date: Fri, 16 Jul 2021 22:10:49 +0800 Subject: [PATCH] Make use of string_util --- src/core/inner_fat.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/inner_fat.hpp b/src/core/inner_fat.hpp index 6ae1b70..bc124f5 100644 --- a/src/core/inner_fat.hpp +++ b/src/core/inner_fat.hpp @@ -13,6 +13,7 @@ #include "common/common_types.h" #include "common/file_util.h" #include "common/logging/log.h" +#include "common/string_util.h" #include "common/swap.h" namespace Core { @@ -292,10 +293,8 @@ public: } const auto& entry = this->directory_entry_table[index]; - std::array name_data = {}; // Append a null terminator - std::memcpy(name_data.data(), entry.name.data(), entry.name.size()); - - const std::string name = name_data.data(); + const std::string name = + Common::StringFromFixedZeroTerminatedBuffer(entry.name.data(), entry.name.size()); std::string new_path = name.empty() ? path : path + name + "/"; // Name is empty for root if (!FileUtil::CreateFullPath(new_path)) { @@ -311,10 +310,10 @@ public: return false; } const auto& file_entry = this->file_entry_table[cur]; - std::memcpy(name_data.data(), file_entry.name.data(), file_entry.name.size()); + const std::string file_name = Common::StringFromFixedZeroTerminatedBuffer( + file_entry.name.data(), file_entry.name.size()); - if (!static_cast(this)->ExtractFile(new_path + std::string{name_data.data()}, - cur)) { + if (!static_cast(this)->ExtractFile(new_path + file_name, cur)) { return false; } cur = this->file_entry_table[cur].next_sibling_index;