Fix assertion failure in NativeProcessProtocolTest
authorPavel Labath <pavel@labath.sk>
Thu, 27 Dec 2018 13:45:55 +0000 (13:45 +0000)
committerPavel Labath <pavel@labath.sk>
Thu, 27 Dec 2018 13:45:55 +0000 (13:45 +0000)
The assertion fired (with a debug visual studio STL) because we tried to
dereference the end of a vector (although it was only to take its
address again and form an end iterator). Rewrite this logic to avoid the
questionable code.

llvm-svn: 350091

lldb/unittests/Host/NativeProcessProtocolTest.cpp

index 39d6362..298c290 100644 (file)
@@ -131,7 +131,8 @@ llvm::Expected<std::vector<uint8_t>> FakeMemory::Read(addr_t Addr,
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "Address out of range.");
   Size = std::min(Size, Data.size() - (size_t)Addr);
-  return std::vector<uint8_t>(&Data[Addr], &Data[Addr + Size]);
+  auto Begin = std::next(Data.begin(), Addr);
+  return std::vector<uint8_t>(Begin, std::next(Begin, Size));
 }
 
 llvm::Expected<size_t> FakeMemory::Write(addr_t Addr,