diff --git a/troposphere/haze/include/haze/event_reactor.hpp b/troposphere/haze/include/haze/event_reactor.hpp index 3968c2a59..e1ab44d64 100644 --- a/troposphere/haze/include/haze/event_reactor.hpp +++ b/troposphere/haze/include/haze/event_reactor.hpp @@ -43,10 +43,10 @@ namespace haze { template Result WaitFor(s32 *out_arg_waiter, Args &&... arg_waiters) { const Waiter arg_waiter_array[] = { arg_waiters... }; - return this->WaitForImpl(out_arg_waiter, sizeof...(Args), arg_waiter_array); + return this->WaitForImpl(out_arg_waiter, arg_waiter_array, sizeof...(Args)); } private: - Result WaitForImpl(s32 *out_arg_waiter, s32 num_arg_waiters, const Waiter *arg_waiters); + Result WaitForImpl(s32 *out_arg_waiter, const Waiter *arg_waiters, s32 num_arg_waiters); }; } diff --git a/troposphere/haze/include/haze/ptp_data_parser.hpp b/troposphere/haze/include/haze/ptp_data_parser.hpp index a30d5dc1f..86b62460a 100644 --- a/troposphere/haze/include/haze/ptp_data_parser.hpp +++ b/troposphere/haze/include/haze/ptp_data_parser.hpp @@ -101,7 +101,7 @@ namespace haze { } /* Write null terminator. */ - *out_string++ = 0; + *out_string++ = '\x00'; R_SUCCEED(); } diff --git a/troposphere/haze/source/async_usb_server.cpp b/troposphere/haze/source/async_usb_server.cpp index ed465ad61..3c45411fb 100644 --- a/troposphere/haze/source/async_usb_server.cpp +++ b/troposphere/haze/source/async_usb_server.cpp @@ -49,6 +49,7 @@ namespace haze { R_THROW(haze::ResultNotConfigured()); } + /* Select the appropriate endpoint and begin a transfer. */ UsbSessionEndpoint ep = read ? UsbSessionEndpoint_Read : UsbSessionEndpoint_Write; R_TRY(s_usb_session.TransferAsync(ep, page, size, std::addressof(urb_id))); diff --git a/troposphere/haze/source/event_reactor.cpp b/troposphere/haze/source/event_reactor.cpp index 724e878d5..1db2abeb5 100644 --- a/troposphere/haze/source/event_reactor.cpp +++ b/troposphere/haze/source/event_reactor.cpp @@ -29,10 +29,10 @@ namespace haze { } void EventReactor::RemoveConsumer(EventConsumer *consumer) { - s32 input_index = 0, output_index = 0; + s32 output_index = 0; /* Remove the consumer. */ - for (; input_index < m_num_wait_objects; input_index++) { + for (s32 input_index = 0; input_index < m_num_wait_objects; input_index++) { if (m_consumers[input_index] == consumer) { continue; } @@ -48,7 +48,7 @@ namespace haze { m_num_wait_objects = output_index; } - Result EventReactor::WaitForImpl(s32 *out_arg_waiter, s32 num_arg_waiters, const Waiter *arg_waiters) { + Result EventReactor::WaitForImpl(s32 *out_arg_waiter, const Waiter *arg_waiters, s32 num_arg_waiters) { HAZE_ASSERT(m_num_wait_objects + num_arg_waiters <= MAX_WAIT_OBJECTS); while (true) { @@ -62,7 +62,7 @@ namespace haze { s32 idx; HAZE_R_ABORT_UNLESS(waitObjects(std::addressof(idx), m_waiters, m_num_wait_objects + num_arg_waiters, -1)); - /* If this refers to a waiter in the argument list, return it. */ + /* If a waiter in the argument list was signaled, return it. */ if (idx >= m_num_wait_objects) { *out_arg_waiter = idx - m_num_wait_objects; R_SUCCEED(); diff --git a/troposphere/haze/source/main.cpp b/troposphere/haze/source/main.cpp index 2f568eb22..c2dfc5b91 100644 --- a/troposphere/haze/source/main.cpp +++ b/troposphere/haze/source/main.cpp @@ -16,7 +16,7 @@ #include #include -int main(int argc, char *argv[]) { +int main(int argc, char **argv) { haze::PtpObjectHeap ptp_object_heap; haze::EventReactor event_reactor; diff --git a/troposphere/haze/source/ptp_object_database.cpp b/troposphere/haze/source/ptp_object_database.cpp index 847f661d3..28883e89e 100644 --- a/troposphere/haze/source/ptp_object_database.cpp +++ b/troposphere/haze/source/ptp_object_database.cpp @@ -38,36 +38,36 @@ namespace haze { } Result PtpObjectDatabase::AddObjectId(const char *parent_name, const char *name, u32 *out_object_id, u32 parent_id, u32 desired_object_id) { - ObjectNode *node = nullptr; - /* Calculate length of the name. */ const size_t parent_name_len = std::strlen(parent_name); const size_t name_len = std::strlen(name) + 1; const size_t alloc_len = parent_name_len + 1 + name_len; /* Allocate memory for the node. */ - node = reinterpret_cast(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len)); + ObjectNode *const node = reinterpret_cast(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len)); R_UNLESS(node != nullptr, haze::ResultOutOfMemory()); - /* Ensure we maintain a clean state on failure. */ - auto guard = SCOPE_GUARD { m_object_heap->Deallocate(node, sizeof(ObjectNode) + alloc_len); }; + { + /* Ensure we maintain a clean state on failure. */ + auto guard = SCOPE_GUARD { m_object_heap->Deallocate(node, sizeof(ObjectNode) + alloc_len); }; - /* Take ownership of the name. */ - std::strncpy(node->m_name, parent_name, parent_name_len + 1); - node->m_name[parent_name_len] = '/'; - std::strncpy(node->m_name + parent_name_len + 1, name, name_len); + /* Take ownership of the name. */ + std::strncpy(node->m_name, parent_name, parent_name_len + 1); + node->m_name[parent_name_len] = '/'; + std::strncpy(node->m_name + parent_name_len + 1, name, name_len); - /* Check if an object with this name already exists. If it does, we can just return it here. */ - auto it = m_name_to_object_id.find_key(node->m_name); - if (it != m_name_to_object_id.end()) { - if (out_object_id) { - *out_object_id = it->GetObjectId(); + /* Check if an object with this name already exists. If it does, we can just return it here. */ + auto it = m_name_to_object_id.find_key(node->m_name); + if (it != m_name_to_object_id.end()) { + if (out_object_id) { + *out_object_id = it->GetObjectId(); + } + R_SUCCEED(); } - R_SUCCEED(); - } - /* Persist the reference to the node. */ - guard.Cancel(); + /* Persist the reference to the node. */ + guard.Cancel(); + } /* Insert node into trees. */ node->m_parent_id = parent_id; diff --git a/troposphere/haze/source/ptp_object_heap.cpp b/troposphere/haze/source/ptp_object_heap.cpp index eadde042e..20d11b94b 100644 --- a/troposphere/haze/source/ptp_object_heap.cpp +++ b/troposphere/haze/source/ptp_object_heap.cpp @@ -20,22 +20,22 @@ namespace haze { namespace { /* Allow 20MiB for use by libnx. */ - static constexpr size_t LibnxReservedMem = 20_MB; + static constexpr size_t LibnxReservedMemorySize = 20_MB; } void PtpObjectHeap::Initialize() { size_t mem_used = 0; - /* Skip re-initialization if we are currently initialized. */ + /* If we're already initialized, skip re-initialization. */ if (m_heap_block_size != 0) { return; } /* Estimate how much memory we can reserve. */ HAZE_R_ABORT_UNLESS(svcGetInfo(std::addressof(mem_used), InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0)); - HAZE_ASSERT(mem_used > LibnxReservedMem); - mem_used -= LibnxReservedMem; + HAZE_ASSERT(mem_used > LibnxReservedMemorySize); + mem_used -= LibnxReservedMemorySize; /* Take the rest for ourselves. */ m_heap_block_size = mem_used / NumHeapBlocks;