Fix dangling reference in DwarfLinker.cpp. The original code
authorYaron Keren <yaron.keren@gmail.com>
Sat, 8 Aug 2015 21:03:19 +0000 (21:03 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Sat, 8 Aug 2015 21:03:19 +0000 (21:03 +0000)
  Seq.emplace_back(Seq.back());

does not work as planned, since Seq.back() may become a dangling reference
when emplace_back is called and possibly reallocates vector. To avoid this,
the vector allocation should be reserved first and only then used.

This broke test/tools/dsymutil/X86/custom-line-table.test with Visual C++ 2013.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244405 91177308-0d34-0410-b5e6-96231b3b80d8

tools/dsymutil/DwarfLinker.cpp

index 47d085047866b5b7c6fbce2ed2ea3286458af580..d839f07657baaf39890d693ffac511d966cfc674 100644 (file)
@@ -2884,6 +2884,7 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit,
       if (StopAddress != -1ULL && !Seq.empty()) {
         // Insert end sequence row with the computed end address, but
         // the same line as the previous one.
+        Seq.reserve(Seq.size() + 1);
         Seq.emplace_back(Seq.back());
         Seq.back().Address = StopAddress;
         Seq.back().EndSequence = 1;