From 350976f5e27ec7054d17abce836c143aabc65621 Mon Sep 17 00:00:00 2001
From: whh8b <whh8b@git.zephyr-software.com>
Date: Mon, 1 Feb 2016 02:05:38 +0000
Subject: [PATCH] Memory space bug fixes

1. A plugin that returns space smaller than "min size"
is not bad if the dollop fits within the space entirely.

2. GetNearbyFreeRanges() should really treat the parameter
as a lower bound.
---
 src/memory_space.cpp | 2 +-
 src/zipr.cpp         | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/memory_space.cpp b/src/memory_space.cpp
index 4d2465d..4788d3c 100644
--- a/src/memory_space.cpp
+++ b/src/memory_space.cpp
@@ -176,7 +176,7 @@ std::pair<RangeSet_t::const_iterator,RangeSet_t::const_iterator>
 	ZiprMemorySpace_t::GetNearbyFreeRanges(const RangeAddress_t hint,size_t count)
 {
 	Range_t search(hint, hint+1);
-	RangeSet_t::const_iterator result = free_ranges.upper_bound(search);
+	RangeSet_t::const_iterator result = free_ranges.lower_bound(search);
 	/*
 	 * TODO: Not quite sure what to make of this.
 	 */
diff --git a/src/zipr.cpp b/src/zipr.cpp
index 7a13e96..744f942 100644
--- a/src/zipr.cpp
+++ b/src/zipr.cpp
@@ -1429,7 +1429,8 @@ void ZiprImpl_t::PlaceDollops()
 						 << std::hex << placement.GetEnd()
 						 << endl;
 
-			if ((placement.GetEnd()-placement.GetStart()) < minimum_valid_req_size){
+			if ((placement.GetEnd()-placement.GetStart()) < minimum_valid_req_size &&
+			    placement.GetEnd()-placement.GetStart() < to_place->GetSize()) {
 				if (m_verbose)
 					cout << "Bad GetNearbyFreeRange() result." << endl;
 				placed = false;
-- 
GitLab