From 8b4ecf22d485958f69ecbd2fa4ca55d9ce393826 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 00:28:35 -0400 Subject: audio_core: Resolve sign conversion warnings While were at it, we can also enable sign conversion warnings and other common warnings as errors to prevent these from creeping back into the codebase. --- src/audio_core/splitter_context.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/audio_core/splitter_context.cpp') diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index 79bb2f516..f21b53147 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -306,7 +306,7 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - if (header.send_id < 0 || header.send_id > info_count) { + if (header.send_id < 0 || static_cast(header.send_id) > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } @@ -348,7 +348,7 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - if (header.splitter_id < 0 || header.splitter_id > data_count) { + if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } @@ -434,7 +434,7 @@ const std::vector& NodeStates::GetIndexList() const { } void NodeStates::PushTsortResult(s32 index) { - ASSERT(index < node_count); + ASSERT(index < static_cast(node_count)); index_list[index_pos++] = index; } -- cgit v1.2.3 From be1954e04cb5a0c3a526f78ed5490a5e65310280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Oct 2020 14:49:45 -0400 Subject: core: Fix clang build Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795 --- src/audio_core/splitter_context.cpp | 60 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'src/audio_core/splitter_context.cpp') diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f21b53147..f3e870648 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) { new_connection = true; // We need to update the size here due to the splitter bug being present and providing an // incorrect size. We're suppose to also update the header here but we just ignore and continue - return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3); + return (sizeof(s32_le) * static_cast(header.length - 1)) + (sizeof(s32_le) * 3); } ServerSplitterDestinationData* ServerSplitterInfo::GetHead() { @@ -306,13 +306,14 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - if (header.send_id < 0 || static_cast(header.send_id) > info_count) { + const auto send_id = static_cast(header.send_id); + if (header.send_id < 0 || send_id > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } UpdateOffsets(sizeof(SplitterInfo::InInfoPrams)); - auto& info = GetInfo(header.send_id); + auto& info = GetInfo(send_id); if (!RecomposeDestination(info, header, input, input_offset)) { LOG_ERROR(Audio, "Failed to recompose destination for splitter!"); return false; @@ -348,11 +349,12 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { + const auto splitter_id = static_cast(header.splitter_id); + if (header.splitter_id < 0 || splitter_id > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } - GetData(header.splitter_id).Update(header); + GetData(splitter_id).Update(header); } return true; } @@ -386,9 +388,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, return true; } - auto* start_head = &GetData(header.resource_id_base); + auto* start_head = &GetData(static_cast(header.resource_id_base)); current_head = start_head; - std::vector resource_ids(size - 1); + std::vector resource_ids(static_cast(size - 1)); if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset, resource_ids.size() * sizeof(s32_le))) { LOG_ERROR(Audio, "Buffer is an invalid size!"); @@ -397,8 +399,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, std::memcpy(resource_ids.data(), input.data() + input_offset, resource_ids.size() * sizeof(s32_le)); - for (auto resource_id : resource_ids) { - auto* head = &GetData(resource_id); + for (const auto resource_id : resource_ids) { + auto* head = &GetData(static_cast(resource_id)); current_head->SetNextDestination(head); current_head = head; } @@ -444,7 +446,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { const auto node_id = static_cast(i); // If we don't have a state, send to our index stack for work - if (GetState(i) == NodeStates::State::NoState) { + if (GetState(i) == State::NoState) { index_stack.push(node_id); } @@ -453,19 +455,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { // Get the current node const auto current_stack_index = index_stack.top(); // Check if we've seen the node yet - const auto index_state = GetState(current_stack_index); - if (index_state == NodeStates::State::NoState) { + const auto index_state = GetState(static_cast(current_stack_index)); + if (index_state == State::NoState) { // Mark the node as seen - UpdateState(NodeStates::State::InFound, current_stack_index); - } else if (index_state == NodeStates::State::InFound) { + UpdateState(State::InFound, static_cast(current_stack_index)); + } else if (index_state == State::InFound) { // We've seen this node before, mark it as completed - UpdateState(NodeStates::State::InCompleted, current_stack_index); + UpdateState(State::InCompleted, static_cast(current_stack_index)); // Update our index list PushTsortResult(current_stack_index); // Pop the stack index_stack.pop(); continue; - } else if (index_state == NodeStates::State::InCompleted) { + } else if (index_state == State::InCompleted) { // If our node is already sorted, clear it index_stack.pop(); continue; @@ -479,11 +481,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { } // Check if our node exists - const auto node_state = GetState(j); - if (node_state == NodeStates::State::NoState) { + const auto node_state = GetState(static_cast(j)); + if (node_state == State::NoState) { // Add more work index_stack.push(j); - } else if (node_state == NodeStates::State::InFound) { + } else if (node_state == State::InFound) { UNREACHABLE_MSG("Node start marked as found"); ResetState(); return false; @@ -507,17 +509,17 @@ void NodeStates::ResetState() { } } -void NodeStates::UpdateState(NodeStates::State state, std::size_t i) { +void NodeStates::UpdateState(State state, std::size_t i) { switch (state) { - case NodeStates::State::NoState: + case State::NoState: was_node_found[i] = false; was_node_completed[i] = false; break; - case NodeStates::State::InFound: + case State::InFound: was_node_found[i] = true; was_node_completed[i] = false; break; - case NodeStates::State::InCompleted: + case State::InCompleted: was_node_found[i] = false; was_node_completed[i] = true; break; @@ -528,13 +530,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) { ASSERT(i < node_count); if (was_node_found[i]) { // If our node exists in our found list - return NodeStates::State::InFound; + return State::InFound; } else if (was_node_completed[i]) { // If node is in the completed list - return NodeStates::State::InCompleted; + return State::InCompleted; } else { // If in neither - return NodeStates::State::NoState; + return State::NoState; } } @@ -601,16 +603,16 @@ std::size_t EdgeMatrix::GetNodeCount() const { void EdgeMatrix::SetState(s32 a, s32 b, bool state) { ASSERT(InRange(a, b)); - edge_matrix.at(a * node_count + b) = state; + edge_matrix.at(static_cast(a) * node_count + static_cast(b)) = state; } bool EdgeMatrix::GetState(s32 a, s32 b) { ASSERT(InRange(a, b)); - return edge_matrix.at(a * node_count + b); + return edge_matrix.at(static_cast(a) * node_count + static_cast(b)); } bool EdgeMatrix::InRange(s32 a, s32 b) const { - const std::size_t pos = a * node_count + b; + const std::size_t pos = static_cast(a) * node_count + static_cast(b); return pos < (node_count * node_count); } -- cgit v1.2.3 From 3d592972dc3fd61cc88771b889eff237e4e03e0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 20 Oct 2020 19:07:39 -0700 Subject: Revert "core: Fix clang build" --- src/audio_core/splitter_context.cpp | 60 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src/audio_core/splitter_context.cpp') diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f3e870648..f21b53147 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) { new_connection = true; // We need to update the size here due to the splitter bug being present and providing an // incorrect size. We're suppose to also update the header here but we just ignore and continue - return (sizeof(s32_le) * static_cast(header.length - 1)) + (sizeof(s32_le) * 3); + return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3); } ServerSplitterDestinationData* ServerSplitterInfo::GetHead() { @@ -306,14 +306,13 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - const auto send_id = static_cast(header.send_id); - if (header.send_id < 0 || send_id > info_count) { + if (header.send_id < 0 || static_cast(header.send_id) > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } UpdateOffsets(sizeof(SplitterInfo::InInfoPrams)); - auto& info = GetInfo(send_id); + auto& info = GetInfo(header.send_id); if (!RecomposeDestination(info, header, input, input_offset)) { LOG_ERROR(Audio, "Failed to recompose destination for splitter!"); return false; @@ -349,12 +348,11 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - const auto splitter_id = static_cast(header.splitter_id); - if (header.splitter_id < 0 || splitter_id > data_count) { + if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } - GetData(splitter_id).Update(header); + GetData(header.splitter_id).Update(header); } return true; } @@ -388,9 +386,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, return true; } - auto* start_head = &GetData(static_cast(header.resource_id_base)); + auto* start_head = &GetData(header.resource_id_base); current_head = start_head; - std::vector resource_ids(static_cast(size - 1)); + std::vector resource_ids(size - 1); if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset, resource_ids.size() * sizeof(s32_le))) { LOG_ERROR(Audio, "Buffer is an invalid size!"); @@ -399,8 +397,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, std::memcpy(resource_ids.data(), input.data() + input_offset, resource_ids.size() * sizeof(s32_le)); - for (const auto resource_id : resource_ids) { - auto* head = &GetData(static_cast(resource_id)); + for (auto resource_id : resource_ids) { + auto* head = &GetData(resource_id); current_head->SetNextDestination(head); current_head = head; } @@ -446,7 +444,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { const auto node_id = static_cast(i); // If we don't have a state, send to our index stack for work - if (GetState(i) == State::NoState) { + if (GetState(i) == NodeStates::State::NoState) { index_stack.push(node_id); } @@ -455,19 +453,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { // Get the current node const auto current_stack_index = index_stack.top(); // Check if we've seen the node yet - const auto index_state = GetState(static_cast(current_stack_index)); - if (index_state == State::NoState) { + const auto index_state = GetState(current_stack_index); + if (index_state == NodeStates::State::NoState) { // Mark the node as seen - UpdateState(State::InFound, static_cast(current_stack_index)); - } else if (index_state == State::InFound) { + UpdateState(NodeStates::State::InFound, current_stack_index); + } else if (index_state == NodeStates::State::InFound) { // We've seen this node before, mark it as completed - UpdateState(State::InCompleted, static_cast(current_stack_index)); + UpdateState(NodeStates::State::InCompleted, current_stack_index); // Update our index list PushTsortResult(current_stack_index); // Pop the stack index_stack.pop(); continue; - } else if (index_state == State::InCompleted) { + } else if (index_state == NodeStates::State::InCompleted) { // If our node is already sorted, clear it index_stack.pop(); continue; @@ -481,11 +479,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { } // Check if our node exists - const auto node_state = GetState(static_cast(j)); - if (node_state == State::NoState) { + const auto node_state = GetState(j); + if (node_state == NodeStates::State::NoState) { // Add more work index_stack.push(j); - } else if (node_state == State::InFound) { + } else if (node_state == NodeStates::State::InFound) { UNREACHABLE_MSG("Node start marked as found"); ResetState(); return false; @@ -509,17 +507,17 @@ void NodeStates::ResetState() { } } -void NodeStates::UpdateState(State state, std::size_t i) { +void NodeStates::UpdateState(NodeStates::State state, std::size_t i) { switch (state) { - case State::NoState: + case NodeStates::State::NoState: was_node_found[i] = false; was_node_completed[i] = false; break; - case State::InFound: + case NodeStates::State::InFound: was_node_found[i] = true; was_node_completed[i] = false; break; - case State::InCompleted: + case NodeStates::State::InCompleted: was_node_found[i] = false; was_node_completed[i] = true; break; @@ -530,13 +528,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) { ASSERT(i < node_count); if (was_node_found[i]) { // If our node exists in our found list - return State::InFound; + return NodeStates::State::InFound; } else if (was_node_completed[i]) { // If node is in the completed list - return State::InCompleted; + return NodeStates::State::InCompleted; } else { // If in neither - return State::NoState; + return NodeStates::State::NoState; } } @@ -603,16 +601,16 @@ std::size_t EdgeMatrix::GetNodeCount() const { void EdgeMatrix::SetState(s32 a, s32 b, bool state) { ASSERT(InRange(a, b)); - edge_matrix.at(static_cast(a) * node_count + static_cast(b)) = state; + edge_matrix.at(a * node_count + b) = state; } bool EdgeMatrix::GetState(s32 a, s32 b) { ASSERT(InRange(a, b)); - return edge_matrix.at(static_cast(a) * node_count + static_cast(b)); + return edge_matrix.at(a * node_count + b); } bool EdgeMatrix::InRange(s32 a, s32 b) const { - const std::size_t pos = static_cast(a) * node_count + static_cast(b); + const std::size_t pos = a * node_count + b; return pos < (node_count * node_count); } -- cgit v1.2.3 From 1ea6bdef058a789e2771511f741bffcca73c3525 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 25 Nov 2020 15:21:03 -0500 Subject: audio_core: Make shadowing and unused parameters errors Moves the audio code closer to enabling warnings as errors in general. --- src/audio_core/splitter_context.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/audio_core/splitter_context.cpp') diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f21b53147..f4bcd0391 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -10,7 +10,7 @@ namespace AudioCore { -ServerSplitterDestinationData::ServerSplitterDestinationData(s32 id) : id(id) {} +ServerSplitterDestinationData::ServerSplitterDestinationData(s32 id_) : id{id_} {} ServerSplitterDestinationData::~ServerSplitterDestinationData() = default; void ServerSplitterDestinationData::Update(SplitterInfo::InDestinationParams& header) { @@ -87,7 +87,7 @@ void ServerSplitterDestinationData::UpdateInternalState() { needs_update = false; } -ServerSplitterInfo::ServerSplitterInfo(s32 id) : id(id) {} +ServerSplitterInfo::ServerSplitterInfo(s32 id_) : id(id_) {} ServerSplitterInfo::~ServerSplitterInfo() = default; void ServerSplitterInfo::InitializeInfos() { @@ -121,7 +121,7 @@ const ServerSplitterDestinationData* ServerSplitterInfo::GetHead() const { } ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) { - auto current_head = head; + auto* current_head = head; for (std::size_t i = 0; i < depth; i++) { if (current_head == nullptr) { return nullptr; @@ -132,7 +132,7 @@ ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) { } const ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) const { - auto current_head = head; + auto* current_head = head; for (std::size_t i = 0; i < depth; i++) { if (current_head == nullptr) { return nullptr; @@ -245,7 +245,7 @@ ServerSplitterDestinationData* SplitterContext::GetDestinationData(std::size_t i const ServerSplitterDestinationData* SplitterContext::GetDestinationData(std::size_t info, std::size_t data) const { ASSERT(info < info_count); - auto& cur_info = GetInfo(info); + const auto& cur_info = GetInfo(info); return cur_info.GetData(data); } @@ -267,11 +267,11 @@ std::size_t SplitterContext::GetDataCount() const { return data_count; } -void SplitterContext::Setup(std::size_t _info_count, std::size_t _data_count, +void SplitterContext::Setup(std::size_t info_count_, std::size_t data_count_, bool is_splitter_bug_fixed) { - info_count = _info_count; - data_count = _data_count; + info_count = info_count_; + data_count = data_count_; for (std::size_t i = 0; i < info_count; i++) { auto& splitter = infos.emplace_back(static_cast(i)); @@ -364,7 +364,7 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, // Clear our current destinations auto* current_head = info.GetHead(); while (current_head != nullptr) { - auto next_head = current_head->GetNextDestination(); + auto* next_head = current_head->GetNextDestination(); current_head->SetNextDestination(nullptr); current_head = next_head; } @@ -471,8 +471,8 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { continue; } - const auto node_count = edge_matrix.GetNodeCount(); - for (s32 j = 0; j < static_cast(node_count); j++) { + const auto edge_node_count = edge_matrix.GetNodeCount(); + for (s32 j = 0; j < static_cast(edge_node_count); j++) { // Check if our node is connected to our edge matrix if (!edge_matrix.Connected(current_stack_index, j)) { continue; -- cgit v1.2.3