MLBEDSW-3843: Segmentation fault search allocator
Vector index could become negative in search allocator.
Change-Id: I3b77474a86fd5f4227d8b2a825d11ec8ec0fb073
Signed-off-by: Louis Verhaard <louis.verhaard@arm.com>
diff --git a/ethosu/tensor_allocator/search_allocator.cpp b/ethosu/tensor_allocator/search_allocator.cpp
index c7c418a..5c7492b 100644
--- a/ethosu/tensor_allocator/search_allocator.cpp
+++ b/ethosu/tensor_allocator/search_allocator.cpp
@@ -68,7 +68,7 @@
}
}
}
- target_size = std::max(min_required_size, available_size);
+ target_size = std::max(min_required_size, size_limit);
// Calculate the urgency of each live range
lr_urgency.resize(lrs.size());
for (size_t i = 0; i < lrs.size(); ++i) {
@@ -217,7 +217,8 @@
// Pick any affecting live range.
ix1 = turn_list[rng() % turn_list.size()];
}
- size_t ix2 = turn_list[rng() % turn_list.size() - 1];
+ // Note: turn_list has always at least 2 elements for bottlenecks
+ size_t ix2 = turn_list[rng() % (turn_list.size() - 1)];
if (ix1 == ix2) {
ix2 = turn_list[turn_list.size() - 1];
}