From 9427d03d5ac3a7ee5ce8f29f051b7c2a3fb63814 Mon Sep 17 00:00:00 2001 From: Rhodan81 Date: Sat, 5 Sep 2015 15:53:05 +0200 Subject: [PATCH] Fix crash in memory allocation when there is no space to fit entire page range --- src/xenia/memory.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index bea9960dc..c7c56cf12 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -650,9 +650,15 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address, // At least one page in the range is used, skip to next. // We know we'll be starting at least before this page. any_taken = true; - base_page_number = page_number - page_count; - base_page_number -= base_page_number % page_scan_stride; - base_page_number += page_scan_stride; // cancel out loop logic + if (page_count > page_number) { + // Not enough space left to fit entire page range. Breaks outer + // loop. + base_page_number = -1; + } else { + base_page_number = page_number - page_count; + base_page_number -= base_page_number % page_scan_stride; + base_page_number += page_scan_stride; // cancel out loop logic + } break; } }