From fcf61f000804a05bc06d708152c15a527c6461cb Mon Sep 17 00:00:00 2001 From: Parshintsev Anatoly Date: Thu, 29 Dec 2022 14:09:08 +0300 Subject: simplify merge_mem_regions by utilizing get_inclusive_end() of mem_cfg_t this is to properly handle potential 64-bit overflow in (base + size) expression --- spike_main/spike.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spike_main') diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 59dbbf3..5a3d995 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -139,9 +139,9 @@ static mem_cfg_t merge_mem_regions(const mem_cfg_t& L, const mem_cfg_t& R) // one can merge only intersecting regions assert(check_mem_overlap(L, R)); - const reg_t merged_base = std::min(L.get_base(), R.get_base()); - const reg_t merged_end_incl = std::max(L.get_base() + L.get_size() - 1, R.get_base() + R.get_size() - 1); - const reg_t merged_size = merged_end_incl - merged_base + 1; + const auto merged_base = std::min(L.get_base(), R.get_base()); + const auto merged_end_incl = std::max(L.get_inclusive_end(), R.get_inclusive_end()); + const auto merged_size = merged_end_incl - merged_base + 1; return mem_cfg_t(merged_base, merged_size); } -- cgit v1.1