Fix Dwarf path handling to fix broken test
authorChip Turner <chip@fb.com>
Tue, 23 Dec 2014 18:19:39 +0000 (10:19 -0800)
committerDave Watson <davejwatson@fb.com>
Mon, 29 Dec 2014 18:40:14 +0000 (10:40 -0800)
Summary:
Simplify the logic slightly to better handle joining paths.
This makes DwarfTest.cpp pass.

Test Plan: runtests

Reviewed By: njormrod@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1756036

Tasks: 5871014

Signature: t1:1756036:1419359254:123cc508b8836ea0b1485abe361b1c158538aa08

folly/experimental/symbolizer/Dwarf.cpp

index d2385aa55619269a5accce649add0edb800a0aa6..03c8e447331252e5ed8f0ba1583bfbf4a0e6dc28 100644 (file)
@@ -257,21 +257,18 @@ size_t Dwarf::Path::toBuffer(char* buf, size_t bufSize) const {
 
 void Dwarf::Path::toString(std::string& dest) const {
   size_t initialSize = dest.size();
-  bool needsSlash = false;
   dest.reserve(initialSize + size());
   if (!baseDir_.empty()) {
     dest.append(baseDir_.begin(), baseDir_.end());
-    needsSlash = baseDir_.endsWith('/');
   }
   if (!subDir_.empty()) {
-    if (needsSlash) {
+    if (!dest.empty() && dest.back() != '/') {
       dest.push_back('/');
     }
     dest.append(subDir_.begin(), subDir_.end());
-    needsSlash = subDir_.endsWith('/');
   }
   if (!file_.empty()) {
-    if (needsSlash) {
+    if (!dest.empty() && dest.back() != '/') {
       dest.push_back('/');
     }
     dest.append(file_.begin(), file_.end());