From 4654f896184fa1b97df5920ef775f033c2b2fcbb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 25 Sep 2018 18:25:10 -0400 Subject: fsmitm_romfsbuild: Avoid type truncation warnings Cast where explicitly necessary and in other cases we can simply modify the algorithm to accomodate larger data. --- src/core/file_sys/fsmitm_romfsbuild.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/core') diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 20dd69570..07b074817 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp @@ -105,13 +105,16 @@ static u32 romfs_calc_path_hash(u32 parent, std::string path, u32 start, std::si return hash; } -static u32 romfs_get_hash_table_count(u32 num_entries) { +static u64 romfs_get_hash_table_count(u64 num_entries) { if (num_entries < 3) { return 3; - } else if (num_entries < 19) { + } + + if (num_entries < 19) { return num_entries | 1; } - u32 count = num_entries; + + u64 count = num_entries; while (count % 2 == 0 || count % 3 == 0 || count % 5 == 0 || count % 7 == 0 || count % 11 == 0 || count % 13 == 0 || count % 17 == 0) { count++; @@ -137,7 +140,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, const auto child = std::make_shared(); // Set child's path. child->cur_path_ofs = parent->path_len + 1; - child->path_len = child->cur_path_ofs + kv.first.size(); + child->path_len = child->cur_path_ofs + static_cast(kv.first.size()); child->path = parent->path + "/" + kv.first; // Sanity check on path_len @@ -150,7 +153,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, const auto child = std::make_shared(); // Set child's path. child->cur_path_ofs = parent->path_len + 1; - child->path_len = child->cur_path_ofs + kv.first.size(); + child->path_len = child->cur_path_ofs + static_cast(kv.first.size()); child->path = parent->path + "/" + kv.first; // Sanity check on path_len @@ -217,8 +220,8 @@ RomFSBuildContext::RomFSBuildContext(VirtualDir base_) : base(std::move(base_)) RomFSBuildContext::~RomFSBuildContext() = default; std::map RomFSBuildContext::Build() { - const auto dir_hash_table_entry_count = romfs_get_hash_table_count(num_dirs); - const auto file_hash_table_entry_count = romfs_get_hash_table_count(num_files); + const u64 dir_hash_table_entry_count = romfs_get_hash_table_count(num_dirs); + const u64 file_hash_table_entry_count = romfs_get_hash_table_count(num_files); dir_hash_table_size = 4 * dir_hash_table_entry_count; file_hash_table_size = 4 * file_hash_table_entry_count; -- cgit v1.2.3