diff options
| author | 2018-08-08 17:49:57 -0400 | |
|---|---|---|
| committer | 2018-08-08 18:51:52 -0400 | |
| commit | 7353cfc7813c960e7fdb0b33829865c606f98c84 (patch) | |
| tree | 65c5bc3a27c0df3229145afb2552993ba72a46be | |
| parent | fsp_srv: Emplace entries first when building index instead of emplacing last (diff) | |
| download | yuzu-7353cfc7813c960e7fdb0b33829865c606f98c84.tar.gz yuzu-7353cfc7813c960e7fdb0b33829865c606f98c84.tar.xz yuzu-7353cfc7813c960e7fdb0b33829865c606f98c84.zip | |
fsp_srv: Use std::string_view's copy() function instead of strncpy()
Given elements inserted into a vector are zeroed out, we can just copy
MAX_LEN - 1 elements and the data will already be properly null
terminated.
| -rw-r--r-- | src/core/file_sys/directory.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 6 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h index 213ce1826..3759e743a 100644 --- a/src/core/file_sys/directory.h +++ b/src/core/file_sys/directory.h | |||
| @@ -4,8 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <iterator> | ||
| 9 | #include <string_view> | ||
| 9 | #include "common/common_funcs.h" | 10 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 11 | 12 | ||
| @@ -21,9 +22,14 @@ enum EntryType : u8 { | |||
| 21 | 22 | ||
| 22 | // Structure of a directory entry, from | 23 | // Structure of a directory entry, from |
| 23 | // http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry | 24 | // http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry |
| 24 | const size_t FILENAME_LENGTH = 0x300; | ||
| 25 | struct Entry { | 25 | struct Entry { |
| 26 | char filename[FILENAME_LENGTH]; | 26 | Entry(std::string_view view, EntryType entry_type, u64 entry_size) |
| 27 | : type{entry_type}, file_size{entry_size} { | ||
| 28 | const size_t copy_size = view.copy(filename, std::size(filename) - 1); | ||
| 29 | filename[copy_size] = '\0'; | ||
| 30 | } | ||
| 31 | |||
| 32 | char filename[0x300]; | ||
| 27 | INSERT_PADDING_BYTES(4); | 33 | INSERT_PADDING_BYTES(4); |
| 28 | EntryType type; | 34 | EntryType type; |
| 29 | INSERT_PADDING_BYTES(3); | 35 | INSERT_PADDING_BYTES(3); |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 4110e67b4..1470f9017 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -196,11 +196,7 @@ static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vec | |||
| 196 | entries.reserve(entries.size() + new_data.size()); | 196 | entries.reserve(entries.size() + new_data.size()); |
| 197 | 197 | ||
| 198 | for (const auto& new_entry : new_data) { | 198 | for (const auto& new_entry : new_data) { |
| 199 | auto& entry = entries.emplace_back(); | 199 | entries.emplace_back(new_entry->GetName(), type, new_entry->GetSize()); |
| 200 | entry.filename[0] = '\0'; | ||
| 201 | std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1); | ||
| 202 | entry.type = type; | ||
| 203 | entry.file_size = new_entry->GetSize(); | ||
| 204 | } | 200 | } |
| 205 | } | 201 | } |
| 206 | 202 | ||