From 1c340c6efad903580904297730d708ce8b947eb6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 15 Apr 2020 15:59:23 -0400 Subject: CMakeLists: Specify -Wextra on linux builds Allows reporting more cases where logic errors may exist, such as implicit fallthrough cases, etc. We currently ignore unused parameters, since we currently have many cases where this is intentional (virtual interfaces). While we're at it, we can also tidy up any existing code that causes warnings. This also uncovered a few bugs as well. --- src/core/arm/arm_interface.cpp | 4 ++-- src/core/file_sys/patch_manager.cpp | 3 ++- src/core/file_sys/registered_cache.cpp | 23 ++++++++++++++--------- src/core/file_sys/vfs_libzip.cpp | 4 ++-- src/core/frontend/framebuffer_layout.cpp | 2 +- src/core/hle/kernel/hle_ipc.cpp | 24 ++++++++++++------------ src/core/hle/service/audio/audren_u.cpp | 2 +- src/core/hle/service/filesystem/filesystem.cpp | 3 ++- src/core/hle/service/filesystem/fsp_srv.cpp | 3 +++ src/core/hle/service/time/time_zone_manager.cpp | 14 +++++++------- src/core/hle/service/vi/vi.cpp | 4 ++-- src/core/memory/dmnt_cheat_vm.cpp | 5 +++-- src/core/telemetry_session.cpp | 6 +++--- 13 files changed, 54 insertions(+), 43 deletions(-) (limited to 'src/core') diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index 7e846ddd5..fb9e616b9 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp @@ -123,7 +123,7 @@ Symbols GetSymbols(VAddr text_offset, Memory::Memory& memory) { std::optional GetSymbolName(const Symbols& symbols, VAddr func_address) { const auto iter = std::find_if(symbols.begin(), symbols.end(), [func_address](const auto& pair) { - const auto& [symbol, name] = pair; + const auto& symbol = pair.first; const auto end_address = symbol.value + symbol.size; return func_address >= symbol.value && func_address < end_address; }); @@ -146,7 +146,7 @@ std::vector ARM_Interface::GetBacktrace() const { auto fp = GetReg(29); auto lr = GetReg(30); while (true) { - out.push_back({"", 0, lr, 0}); + out.push_back({"", 0, lr, 0, ""}); if (!fp) { break; } diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index e77e82b8d..81ec06cd4 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -440,7 +440,8 @@ std::map> PatchManager::GetPatchVersionNam // Game Updates const auto update_tid = GetUpdateTitleID(title_id); PatchManager update{update_tid}; - auto [nacp, discard_icon_file] = update.GetControlMetadata(); + const auto metadata = update.GetControlMetadata(); + const auto& nacp = metadata.first; const auto update_disabled = std::find(disabled.cbegin(), disabled.cend(), "Update") != disabled.cend(); diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 6e9cf67ef..ba5f76288 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -591,14 +591,18 @@ InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_ex InstallResult RegisteredCache::InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists, const VfsCopyFunction& copy) { CNMTHeader header{ - nca.GetTitleId(), ///< Title ID - 0, ///< Ignore/Default title version - type, ///< Type - {}, ///< Padding - 0x10, ///< Default table offset - 1, ///< 1 Content Entry - 0, ///< No Meta Entries - {}, ///< Padding + nca.GetTitleId(), // Title ID + 0, // Ignore/Default title version + type, // Type + {}, // Padding + 0x10, // Default table offset + 1, // 1 Content Entry + 0, // No Meta Entries + {}, // Padding + {}, // Reserved 1 + 0, // Is committed + 0, // Required download system version + {}, // Reserved 2 }; OptionalHeader opt_header{0, 0}; ContentRecord c_rec{{}, {}, {}, GetCRTypeFromNCAType(nca.GetType()), {}}; @@ -848,7 +852,8 @@ VirtualFile ManualContentProvider::GetEntryUnparsed(u64 title_id, ContentRecordT VirtualFile ManualContentProvider::GetEntryRaw(u64 title_id, ContentRecordType type) const { const auto iter = std::find_if(entries.begin(), entries.end(), [title_id, type](const auto& entry) { - const auto [title_type, content_type, e_title_id] = entry.first; + const auto content_type = std::get<1>(entry.first); + const auto e_title_id = std::get<2>(entry.first); return content_type == type && e_title_id == title_id; }); if (iter == entries.end()) diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp index 11d1978ea..d69952940 100644 --- a/src/core/file_sys/vfs_libzip.cpp +++ b/src/core/file_sys/vfs_libzip.cpp @@ -42,11 +42,11 @@ VirtualDir ExtractZIP(VirtualFile file) { continue; if (name.back() != '/') { - std::unique_ptr file{ + std::unique_ptr file2{ zip_fopen_index(zip.get(), i, 0), zip_fclose}; std::vector buf(stat.size); - if (zip_fread(file.get(), buf.data(), buf.size()) != buf.size()) + if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size())) return nullptr; const auto parts = FileUtil::SplitPathComponents(stat.name); diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index 68a0e0906..d0c43447c 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp @@ -25,7 +25,7 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height) { ASSERT(height > 0); // The drawing code needs at least somewhat valid values for both screens // so just calculate them both even if the other isn't showing. - FramebufferLayout res{width, height}; + FramebufferLayout res{width, height, false, {}}; const float window_aspect_ratio = static_cast(height) / width; const float emulation_aspect_ratio = EmulationAspectRatio( diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index c558a2f33..d65dae3ae 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -284,17 +284,17 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { std::vector HLERequestContext::ReadBuffer(int buffer_index) const { std::vector buffer; - const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && + const bool is_buffer_a{BufferDescriptorA().size() > std::size_t(buffer_index) && BufferDescriptorA()[buffer_index].Size()}; auto& memory = Core::System::GetInstance().Memory(); if (is_buffer_a) { - ASSERT_MSG(BufferDescriptorA().size() > buffer_index, + ASSERT_MSG(BufferDescriptorA().size() > std::size_t(buffer_index), "BufferDescriptorA invalid buffer_index {}", buffer_index); buffer.resize(BufferDescriptorA()[buffer_index].Size()); memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size()); } else { - ASSERT_MSG(BufferDescriptorX().size() > buffer_index, + ASSERT_MSG(BufferDescriptorX().size() > std::size_t(buffer_index), "BufferDescriptorX invalid buffer_index {}", buffer_index); buffer.resize(BufferDescriptorX()[buffer_index].Size()); memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size()); @@ -310,7 +310,7 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, return 0; } - const bool is_buffer_b{BufferDescriptorB().size() > buffer_index && + const bool is_buffer_b{BufferDescriptorB().size() > std::size_t(buffer_index) && BufferDescriptorB()[buffer_index].Size()}; const std::size_t buffer_size{GetWriteBufferSize(buffer_index)}; if (size > buffer_size) { @@ -321,13 +321,13 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, auto& memory = Core::System::GetInstance().Memory(); if (is_buffer_b) { - ASSERT_MSG(BufferDescriptorB().size() > buffer_index, + ASSERT_MSG(BufferDescriptorB().size() > std::size_t(buffer_index), "BufferDescriptorB invalid buffer_index {}", buffer_index); ASSERT_MSG(BufferDescriptorB()[buffer_index].Size() >= size, "BufferDescriptorB buffer_index {} is not large enough", buffer_index); memory.WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size); } else { - ASSERT_MSG(BufferDescriptorC().size() > buffer_index, + ASSERT_MSG(BufferDescriptorC().size() > std::size_t(buffer_index), "BufferDescriptorC invalid buffer_index {}", buffer_index); ASSERT_MSG(BufferDescriptorC()[buffer_index].Size() >= size, "BufferDescriptorC buffer_index {} is not large enough", buffer_index); @@ -338,16 +338,16 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, } std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { - const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && + const bool is_buffer_a{BufferDescriptorA().size() > std::size_t(buffer_index) && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { - ASSERT_MSG(BufferDescriptorA().size() > buffer_index, + ASSERT_MSG(BufferDescriptorA().size() > std::size_t(buffer_index), "BufferDescriptorA invalid buffer_index {}", buffer_index); ASSERT_MSG(BufferDescriptorA()[buffer_index].Size() > 0, "BufferDescriptorA buffer_index {} is empty", buffer_index); return BufferDescriptorA()[buffer_index].Size(); } else { - ASSERT_MSG(BufferDescriptorX().size() > buffer_index, + ASSERT_MSG(BufferDescriptorX().size() > std::size_t(buffer_index), "BufferDescriptorX invalid buffer_index {}", buffer_index); ASSERT_MSG(BufferDescriptorX()[buffer_index].Size() > 0, "BufferDescriptorX buffer_index {} is empty", buffer_index); @@ -356,14 +356,14 @@ std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { } std::size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const { - const bool is_buffer_b{BufferDescriptorB().size() > buffer_index && + const bool is_buffer_b{BufferDescriptorB().size() > std::size_t(buffer_index) && BufferDescriptorB()[buffer_index].Size()}; if (is_buffer_b) { - ASSERT_MSG(BufferDescriptorB().size() > buffer_index, + ASSERT_MSG(BufferDescriptorB().size() > std::size_t(buffer_index), "BufferDescriptorB invalid buffer_index {}", buffer_index); return BufferDescriptorB()[buffer_index].Size(); } else { - ASSERT_MSG(BufferDescriptorC().size() > buffer_index, + ASSERT_MSG(BufferDescriptorC().size() > std::size_t(buffer_index), "BufferDescriptorC invalid buffer_index {}", buffer_index); return BufferDescriptorC()[buffer_index].Size(); } diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 82a5dbf14..175cabf45 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -129,7 +129,7 @@ private: LOG_DEBUG(Service_Audio, "called. rendering_time_limit_percent={}", rendering_time_limit_percent); - ASSERT(rendering_time_limit_percent >= 0 && rendering_time_limit_percent <= 100); + ASSERT(rendering_time_limit_percent <= 100); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 102017d73..cadc03805 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -451,7 +451,8 @@ FileSys::SaveDataSize FileSystemController::ReadSaveDataSize(FileSys::SaveDataTy if (res != Loader::ResultStatus::Success) { FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()}; - auto [nacp_unique, discard] = pm.GetControlMetadata(); + const auto metadata = pm.GetControlMetadata(); + const auto& nacp_unique = metadata.first; if (nacp_unique != nullptr) { new_size = {nacp_unique->GetDefaultNormalSaveSize(), diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index e6811d5b5..61045c75c 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -575,6 +575,7 @@ private: 0, user_id->GetSize(), {}, + {}, }); continue; @@ -595,6 +596,7 @@ private: stoull_be(title_id->GetName()), title_id->GetSize(), {}, + {}, }); } } @@ -619,6 +621,7 @@ private: stoull_be(title_id->GetName()), title_id->GetSize(), {}, + {}, }); } } diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp index 07b553a43..c8159bcd5 100644 --- a/src/core/hle/service/time/time_zone_manager.cpp +++ b/src/core/hle/service/time/time_zone_manager.cpp @@ -309,7 +309,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { offset = GetTZName(name, offset); std_len = offset; } - if (!std_len) { + if (std_len == 0) { return {}; } if (!GetOffset(name, offset, std_offset)) { @@ -320,7 +320,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { int dest_len{}; int dest_offset{}; const char* dest_name{name + offset}; - if (rule.chars.size() < char_count) { + if (rule.chars.size() < std::size_t(char_count)) { return {}; } @@ -343,7 +343,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { return {}; } char_count += dest_len + 1; - if (rule.chars.size() < char_count) { + if (rule.chars.size() < std::size_t(char_count)) { return {}; } if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { @@ -414,7 +414,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { if (is_reversed || (start_time < end_time && (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { - if (rule.ats.size() - 2 < time_count) { + if (rule.ats.size() - 2 < std::size_t(time_count)) { break; } @@ -609,7 +609,7 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi } const u64 position{(read_offset - sizeof(TzifHeader))}; - const std::size_t bytes_read{vfs_file->GetSize() - sizeof(TzifHeader) - position}; + const s64 bytes_read = s64(vfs_file->GetSize() - sizeof(TzifHeader) - position); if (bytes_read < 0) { return {}; } @@ -621,11 +621,11 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi std::array temp_name{}; vfs_file->ReadArray(temp_name.data(), bytes_read, read_offset); if (bytes_read > 2 && temp_name[0] == '\n' && temp_name[bytes_read - 1] == '\n' && - time_zone_rule.type_count + 2 <= time_zone_rule.ttis.size()) { + std::size_t(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { temp_name[bytes_read - 1] = '\0'; std::array name{}; - std::memcpy(name.data(), temp_name.data() + 1, bytes_read - 1); + std::memcpy(name.data(), temp_name.data() + 1, std::size_t(bytes_read - 1)); TimeZoneRule temp_rule; if (ParsePosixName(name.data(), temp_rule)) { diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index fdc62d05b..7f109f4eb 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -101,8 +101,8 @@ public: } std::u16string ReadInterfaceToken() { - u32 unknown = Read(); - u32 length = Read(); + [[maybe_unused]] const u32 unknown = Read(); + const u32 length = Read(); std::u16string token{}; diff --git a/src/core/memory/dmnt_cheat_vm.cpp b/src/core/memory/dmnt_cheat_vm.cpp index 4f4fa5099..5bb26a36f 100644 --- a/src/core/memory/dmnt_cheat_vm.cpp +++ b/src/core/memory/dmnt_cheat_vm.cpp @@ -55,7 +55,7 @@ void DmntCheatVm::LogOpcode(const CheatVmOpcode& opcode) { fmt::format("Cond Type: {:X}", static_cast(begin_cond->cond_type))); callbacks->CommandLog(fmt::format("Rel Addr: {:X}", begin_cond->rel_address)); callbacks->CommandLog(fmt::format("Value: {:X}", begin_cond->value.bit64)); - } else if (auto end_cond = std::get_if(&opcode.opcode)) { + } else if (std::holds_alternative(opcode.opcode)) { callbacks->CommandLog("Opcode: End Conditional"); } else if (auto ctrl_loop = std::get_if(&opcode.opcode)) { if (ctrl_loop->start_loop) { @@ -399,6 +399,7 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { // 8kkkkkkk // Just parse the mask. begin_keypress_cond.key_mask = first_dword & 0x0FFFFFFF; + opcode.opcode = begin_keypress_cond; } break; case CheatVmOpcodeType::PerformArithmeticRegister: { PerformArithmeticRegisterOpcode perform_math_reg{}; @@ -779,7 +780,7 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) { if (!cond_met) { SkipConditionalBlock(); } - } else if (auto end_cond = std::get_if(&cur_opcode.opcode)) { + } else if (std::holds_alternative(cur_opcode.opcode)) { // Decrement the condition depth. // We will assume, graciously, that mismatched conditional block ends are a nop. if (condition_depth > 0) { diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 0f3685d1c..fd5a3ee9f 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -153,9 +153,9 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) { app_loader.ReadTitle(name); if (name.empty()) { - auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata(); - if (nacp != nullptr) { - name = nacp->GetApplicationName(); + const auto metadata = FileSys::PatchManager(program_id).GetControlMetadata(); + if (metadata.first != nullptr) { + name = metadata.first->GetApplicationName(); } } -- cgit v1.2.3