From 6ab839462c2d109781320bc09579b1e370c16395 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 2 Mar 2021 17:44:02 -0800 Subject: [PATCH] video_core: rasterizer_accelerated: Improve error handling & fix implicit conversion. --- src/video_core/rasterizer_accelerated.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/video_core/rasterizer_accelerated.cpp b/src/video_core/rasterizer_accelerated.cpp index c54b17670..f684cd7e5 100644 --- a/src/video_core/rasterizer_accelerated.cpp +++ b/src/video_core/rasterizer_accelerated.cpp @@ -20,9 +20,15 @@ void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int del for (auto page = addr >> Core::Memory::PAGE_BITS; page != page_end; ++page) { auto& count = cached_pages.at(page >> 3).Count(page); - ASSERT_MSG(count < UINT8_MAX, "Count may exceed UINT8_MAX!"); + if (delta < 0) { + ASSERT_MSG(count > 0, "Count may underflow!"); + } else if (delta > 0) { + ASSERT_MSG(count < UINT8_MAX, "Count may overflow!"); + } else { + ASSERT_MSG(true, "Delta must be non-zero!"); + } - count += delta; + count += static_cast(delta); // Assume delta is either -1 or 1 if (count == 0) { @@ -31,8 +37,6 @@ void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int del } else if (count == 1 && delta > 0) { cpu_memory.RasterizerMarkRegionCached(page << Core::Memory::PAGE_BITS, Core::Memory::PAGE_SIZE, true); - } else { - ASSERT(count >= 0); } } }