From f3b6d2930d4aac4a217da5d6edb8413626b9e713 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 30 May 2018 19:46:47 +0000 Subject: [PATCH] [lldb-test] ir-memory-map: Avoid accessing a bad iterator Do not access Probe.start() when Probe is at the end of the interval map. llvm-svn: 333585 --- lldb/tools/lldb-test/lldb-test.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp index 0bfc52a20114..7f9cd6ba8419 100644 --- a/lldb/tools/lldb-test/lldb-test.cpp +++ b/lldb/tools/lldb-test/lldb-test.cpp @@ -551,17 +551,15 @@ bool opts::irmemorymap::evalMalloc(IRMemoryMap &IRMemMap, StringRef Line, auto Probe = AllocatedIntervals.begin(); Probe.advanceTo(Addr); //< First interval s.t stop >= Addr. AllocationT NewAllocation = {Addr, EndOfRegion}; - if (Probe != AllocatedIntervals.end()) { - while (Probe.start() < EndOfRegion) { - AllocationT ProbeAllocation = {Probe.start(), Probe.stop()}; - if (areAllocationsOverlapping(ProbeAllocation, NewAllocation)) { - outs() << "Malloc error: overlapping allocation detected" - << formatv(", previous allocation at [{0:x}, {1:x})\n", - Probe.start(), Probe.stop()); - exit(1); - } - ++Probe; + while (Probe != AllocatedIntervals.end() && Probe.start() < EndOfRegion) { + AllocationT ProbeAllocation = {Probe.start(), Probe.stop()}; + if (areAllocationsOverlapping(ProbeAllocation, NewAllocation)) { + outs() << "Malloc error: overlapping allocation detected" + << formatv(", previous allocation at [{0:x}, {1:x})\n", + Probe.start(), Probe.stop()); + exit(1); } + ++Probe; } // Insert the new allocation into the interval map.