summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar LC2020-10-20 19:19:12 -0400
committerGravatar GitHub2020-10-20 19:19:12 -0400
commit88d5140cf2f80d51dc297af3a128a4212215149f (patch)
treecd524e8ab111fba79f75a48cc672cb875251a32f /src/core/file_sys
parentMerge pull request #4390 from ogniK5377/get-applet-inf-stub (diff)
parentcore: Fix clang build (diff)
downloadyuzu-88d5140cf2f80d51dc297af3a128a4212215149f.tar.gz
yuzu-88d5140cf2f80d51dc297af3a128a4212215149f.tar.xz
yuzu-88d5140cf2f80d51dc297af3a128a4212215149f.zip
Merge pull request #4796 from lioncash/clang
core: Fix clang build
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/content_archive.cpp4
-rw-r--r--src/core/file_sys/fsmitm_romfsbuild.cpp2
-rw-r--r--src/core/file_sys/ips_layer.cpp41
-rw-r--r--src/core/file_sys/kernel_executable.cpp6
-rw-r--r--src/core/file_sys/nca_patch.cpp7
5 files changed, 37 insertions, 23 deletions
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 76af47ff9..0917f6ebf 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -201,9 +201,9 @@ bool NCA::HandlePotentialHeaderDecryption() {
201} 201}
202 202
203std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const { 203std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const {
204 const std::ptrdiff_t number_sections = 204 const auto number_sections = static_cast<std::size_t>(
205 std::count_if(std::begin(header.section_tables), std::end(header.section_tables), 205 std::count_if(std::begin(header.section_tables), std::end(header.section_tables),
206 [](NCASectionTableEntry entry) { return entry.media_offset > 0; }); 206 [](NCASectionTableEntry entry) { return entry.media_offset > 0; }));
207 207
208 std::vector<NCASectionHeader> sections(number_sections); 208 std::vector<NCASectionHeader> sections(number_sections);
209 const auto length_sections = SECTION_HEADER_SIZE * number_sections; 209 const auto length_sections = SECTION_HEADER_SIZE * number_sections;
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp
index c52fafb6f..b2d38f01e 100644
--- a/src/core/file_sys/fsmitm_romfsbuild.cpp
+++ b/src/core/file_sys/fsmitm_romfsbuild.cpp
@@ -103,7 +103,7 @@ static u32 romfs_calc_path_hash(u32 parent, std::string_view path, u32 start,
103 u32 hash = parent ^ 123456789; 103 u32 hash = parent ^ 123456789;
104 for (u32 i = 0; i < path_len; i++) { 104 for (u32 i = 0; i < path_len; i++) {
105 hash = (hash >> 5) | (hash << 27); 105 hash = (hash >> 5) | (hash << 27);
106 hash ^= path[start + i]; 106 hash ^= static_cast<u32>(path[start + i]);
107 } 107 }
108 108
109 return hash; 109 return hash;
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp
index a6101f1c0..91dc69373 100644
--- a/src/core/file_sys/ips_layer.cpp
+++ b/src/core/file_sys/ips_layer.cpp
@@ -66,12 +66,14 @@ static bool IsEOF(IPSFileType type, const std::vector<u8>& data) {
66} 66}
67 67
68VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { 68VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) {
69 if (in == nullptr || ips == nullptr) 69 if (in == nullptr || ips == nullptr) {
70 return nullptr; 70 return nullptr;
71 }
71 72
72 const auto type = IdentifyMagic(ips->ReadBytes(0x5)); 73 const auto type = IdentifyMagic(ips->ReadBytes(0x5));
73 if (type == IPSFileType::Error) 74 if (type == IPSFileType::Error) {
74 return nullptr; 75 return nullptr;
76 }
75 77
76 auto in_data = in->ReadAllBytes(); 78 auto in_data = in->ReadAllBytes();
77 79
@@ -84,37 +86,46 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) {
84 } 86 }
85 87
86 u32 real_offset{}; 88 u32 real_offset{};
87 if (type == IPSFileType::IPS32) 89 if (type == IPSFileType::IPS32) {
88 real_offset = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]; 90 real_offset = static_cast<u32>(temp[0] << 24) | static_cast<u32>(temp[1] << 16) |
89 else 91 static_cast<u32>(temp[2] << 8) | temp[3];
90 real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; 92 } else {
93 real_offset =
94 static_cast<u32>(temp[0] << 16) | static_cast<u32>(temp[1] << 8) | temp[2];
95 }
91 96
92 u16 data_size{}; 97 u16 data_size{};
93 if (ips->ReadObject(&data_size, offset) != sizeof(u16)) 98 if (ips->ReadObject(&data_size, offset) != sizeof(u16)) {
94 return nullptr; 99 return nullptr;
100 }
95 data_size = Common::swap16(data_size); 101 data_size = Common::swap16(data_size);
96 offset += sizeof(u16); 102 offset += sizeof(u16);
97 103
98 if (data_size == 0) { // RLE 104 if (data_size == 0) { // RLE
99 u16 rle_size{}; 105 u16 rle_size{};
100 if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) 106 if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) {
101 return nullptr; 107 return nullptr;
108 }
102 rle_size = Common::swap16(rle_size); 109 rle_size = Common::swap16(rle_size);
103 offset += sizeof(u16); 110 offset += sizeof(u16);
104 111
105 const auto data = ips->ReadByte(offset++); 112 const auto data = ips->ReadByte(offset++);
106 if (!data) 113 if (!data) {
107 return nullptr; 114 return nullptr;
115 }
108 116
109 if (real_offset + rle_size > in_data.size()) 117 if (real_offset + rle_size > in_data.size()) {
110 rle_size = static_cast<u16>(in_data.size() - real_offset); 118 rle_size = static_cast<u16>(in_data.size() - real_offset);
119 }
111 std::memset(in_data.data() + real_offset, *data, rle_size); 120 std::memset(in_data.data() + real_offset, *data, rle_size);
112 } else { // Standard Patch 121 } else { // Standard Patch
113 auto read = data_size; 122 auto read = data_size;
114 if (real_offset + read > in_data.size()) 123 if (real_offset + read > in_data.size()) {
115 read = static_cast<u16>(in_data.size() - real_offset); 124 read = static_cast<u16>(in_data.size() - real_offset);
116 if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) 125 }
126 if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) {
117 return nullptr; 127 return nullptr;
128 }
118 offset += data_size; 129 offset += data_size;
119 } 130 }
120 } 131 }
@@ -182,14 +193,16 @@ void IPSwitchCompiler::ParseFlag(const std::string& line) {
182void IPSwitchCompiler::Parse() { 193void IPSwitchCompiler::Parse() {
183 const auto bytes = patch_text->ReadAllBytes(); 194 const auto bytes = patch_text->ReadAllBytes();
184 std::stringstream s; 195 std::stringstream s;
185 s.write(reinterpret_cast<const char*>(bytes.data()), bytes.size()); 196 s.write(reinterpret_cast<const char*>(bytes.data()),
197 static_cast<std::streamsize>(bytes.size()));
186 198
187 std::vector<std::string> lines; 199 std::vector<std::string> lines;
188 std::string stream_line; 200 std::string stream_line;
189 while (std::getline(s, stream_line)) { 201 while (std::getline(s, stream_line)) {
190 // Remove a trailing \r 202 // Remove a trailing \r
191 if (!stream_line.empty() && stream_line.back() == '\r') 203 if (!stream_line.empty() && stream_line.back() == '\r') {
192 stream_line.pop_back(); 204 stream_line.pop_back();
205 }
193 lines.push_back(std::move(stream_line)); 206 lines.push_back(std::move(stream_line));
194 } 207 }
195 208
diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp
index ef93ef3ed..fa758b777 100644
--- a/src/core/file_sys/kernel_executable.cpp
+++ b/src/core/file_sys/kernel_executable.cpp
@@ -36,14 +36,14 @@ bool DecompressBLZ(std::vector<u8>& data) {
36 while (out_index > 0) { 36 while (out_index > 0) {
37 --index; 37 --index;
38 auto control = data[index + start_offset]; 38 auto control = data[index + start_offset];
39 for (size_t i = 0; i < 8; ++i) { 39 for (std::size_t i = 0; i < 8; ++i) {
40 if (((control << i) & 0x80) > 0) { 40 if (((control << i) & 0x80) > 0) {
41 if (index < 2) { 41 if (index < 2) {
42 return false; 42 return false;
43 } 43 }
44 index -= 2; 44 index -= 2;
45 std::size_t segment_offset = 45 std::size_t segment_offset = static_cast<u32>(data[index + start_offset]) |
46 data[index + start_offset] | data[index + start_offset + 1] << 8; 46 static_cast<u32>(data[index + start_offset + 1] << 8);
47 std::size_t segment_size = ((segment_offset >> 12) & 0xF) + 3; 47 std::size_t segment_size = ((segment_offset >> 12) & 0xF) + 3;
48 segment_offset &= 0xFFF; 48 segment_offset &= 0xFFF;
49 segment_offset += 3; 49 segment_offset += 3;
diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp
index 5990a2fd5..6d3472447 100644
--- a/src/core/file_sys/nca_patch.cpp
+++ b/src/core/file_sys/nca_patch.cpp
@@ -25,9 +25,9 @@ std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, const BlockTyp
25 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block."); 25 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block.");
26 } 26 }
27 27
28 std::size_t bucket_id = std::count_if( 28 const auto bucket_id = static_cast<std::size_t>(std::count_if(
29 block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets, 29 block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets,
30 [&offset](u64 base_offset) { return base_offset <= offset; }); 30 [&offset](u64 base_offset) { return base_offset <= offset; }));
31 31
32 const auto& bucket = buckets[bucket_id]; 32 const auto& bucket = buckets[bucket_id];
33 33
@@ -53,6 +53,7 @@ std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, const BlockTyp
53 } 53 }
54 54
55 UNREACHABLE_MSG("Offset could not be found in BKTR block."); 55 UNREACHABLE_MSG("Offset could not be found in BKTR block.");
56 return {};
56} 57}
57} // Anonymous namespace 58} // Anonymous namespace
58 59
@@ -136,7 +137,7 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
136 137
137 const auto block_offset = section_offset & 0xF; 138 const auto block_offset = section_offset & 0xF;
138 if (block_offset != 0) { 139 if (block_offset != 0) {
139 auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xF); 140 auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xFU);
140 cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt); 141 cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt);
141 if (length + block_offset < 0x10) { 142 if (length + block_offset < 0x10) {
142 std::memcpy(data, block.data() + block_offset, std::min(length, block.size())); 143 std::memcpy(data, block.data() + block_offset, std::min(length, block.size()));