summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/nca_metadata.cpp
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-08-12 21:55:44 +0200
committerZach Hilman <zachhilman@gmail.com>2018-08-12 21:55:44 +0200
commit35e4a47be0c4ef25f860d51851d2c02c02dff53d (patch)
treee1ef42bdd5e4e2bdfc7bd3a0abf0e35cbc912dbd /src/core/file_sys/nca_metadata.cpp
parentregistration: Add support for force overwrite of installed (diff)
downloadyuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.gz
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.bz2
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.lz
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.xz
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.zst
yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.zip
Diffstat (limited to 'src/core/file_sys/nca_metadata.cpp')
-rw-r--r--src/core/file_sys/nca_metadata.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp
index 234d70199..449244444 100644
--- a/src/core/file_sys/nca_metadata.cpp
+++ b/src/core/file_sys/nca_metadata.cpp
@@ -103,7 +103,10 @@ bool CNMT::UnionRecords(const CNMT& other) {
std::vector<u8> CNMT::Serialize() const {
const bool has_opt_header =
header.type >= TitleType::Application && header.type <= TitleType::AOC;
- std::vector<u8> out(sizeof(CNMTHeader) + (has_opt_header ? sizeof(OptionalHeader) : 0));
+ const auto dead_zone = header.table_offset + sizeof(CNMTHeader);
+ std::vector<u8> out(
+ std::max(sizeof(CNMTHeader) + (has_opt_header ? sizeof(OptionalHeader) : 0), dead_zone) +
+ content_records.size() * sizeof(ContentRecord) + meta_records.size() * sizeof(MetaRecord));
memcpy(out.data(), &header, sizeof(CNMTHeader));
// Optional Header
@@ -113,17 +116,11 @@ std::vector<u8> CNMT::Serialize() const {
auto offset = header.table_offset;
- const auto dead_zone = offset + sizeof(CNMTHeader) - out.size();
- if (dead_zone > 0)
- out.resize(offset + sizeof(CNMTHeader));
-
- out.resize(out.size() + content_records.size() * sizeof(ContentRecord));
for (const auto& rec : content_records) {
memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(ContentRecord));
offset += sizeof(ContentRecord);
}
- out.resize(out.size() + content_records.size() * sizeof(MetaRecord));
for (const auto& rec : meta_records) {
memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(MetaRecord));
offset += sizeof(MetaRecord);