diff --git a/troposphere/haze/include/haze/console_main_loop.hpp b/troposphere/haze/include/haze/console_main_loop.hpp index 0db7caa33..359e9523f 100644 --- a/troposphere/haze/include/haze/console_main_loop.hpp +++ b/troposphere/haze/include/haze/console_main_loop.hpp @@ -61,9 +61,13 @@ namespace haze { Result Initialize(EventReactor *reactor, PtpObjectHeap *object_heap) { /* Register event reactor and heap. */ - m_reactor = reactor; + m_reactor = reactor; m_object_heap = object_heap; + /* Set cached use amounts to invalid values. */ + m_last_heap_used = 0xffffffffu; + m_last_heap_total = 0xffffffffu; + /* Get whether we are launched in applet mode. */ AppletType applet_type = appletGetAppletType(); m_is_applet_mode = applet_type != AppletType_Application && applet_type != AppletType_SystemApplication; @@ -104,9 +108,9 @@ namespace haze { private: void RedrawConsole() { /* Get use amounts from the heap. */ - u32 heap_used = m_object_heap->GetUsedSize(); + u32 heap_used = m_object_heap->GetUsedSize(); u32 heap_total = m_object_heap->GetTotalSize(); - u32 heap_pct = heap_total > 0 ? static_cast((heap_used * 100ul) / heap_total) : 0; + u32 heap_pct = heap_total > 0 ? static_cast((heap_used * 100ul) / heap_total) : 0; if (heap_used == m_last_heap_used && heap_total == m_last_heap_total) { /* If usage didn't change, skip redrawing the console. */ @@ -115,7 +119,7 @@ namespace haze { } /* Update cached use amounts. */ - m_last_heap_used = heap_used; + m_last_heap_used = heap_used; m_last_heap_total = heap_total; /* Determine units to use for printing to the console. */ diff --git a/troposphere/haze/include/haze/ptp_object_heap.hpp b/troposphere/haze/include/haze/ptp_object_heap.hpp index ae333588f..e6e6c8ee7 100644 --- a/troposphere/haze/include/haze/ptp_object_heap.hpp +++ b/troposphere/haze/include/haze/ptp_object_heap.hpp @@ -87,13 +87,13 @@ namespace haze { public: template constexpr T *Allocate(size_t n) { - /* Check for overflow. */ - if (!util::CanAddWithoutOverflow(n, 7ul)) { + /* Check for overflow in alignment. */ + if (!util::CanAddWithoutOverflow(n, alignof(u64) - 1)) { return nullptr; } - /* Round up the amount to a multiple of 8. */ - n = util::AlignUp(n, 8); + /* Align the amount to satisfy allocation for u64. */ + n = util::AlignUp(n, alignof(u64)); /* Check if the allocation is possible. */ if (!this->AllocationIsPossible(n)) { diff --git a/troposphere/haze/source/ptp_object_database.cpp b/troposphere/haze/source/ptp_object_database.cpp index 8dcce5261..30aa80e3e 100644 --- a/troposphere/haze/source/ptp_object_database.cpp +++ b/troposphere/haze/source/ptp_object_database.cpp @@ -44,7 +44,7 @@ namespace haze { const size_t alloc_len = parent_name_len + 1 + name_len; /* Allocate memory for the node. */ - ObjectNode * const node = reinterpret_cast(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len)); + ObjectNode * const node = m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len); R_UNLESS(node != nullptr, haze::ResultOutOfMemory()); {