[clang-tools-extra] r294309 - [clangd] Fix subtle use after return.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 7 06:35:09 PST 2017


Author: d0k
Date: Tue Feb  7 08:35:09 2017
New Revision: 294309

URL: http://llvm.org/viewvc/llvm-project?rev=294309&view=rev
Log:
[clangd] Fix subtle use after return.

I didn't find this because my main development machine still happens to
use libstdc++ with the broken C++11 ABI, which has a global empty
string.

Modified:
    clang-tools-extra/trunk/clangd/DocumentStore.h

Modified: clang-tools-extra/trunk/clangd/DocumentStore.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DocumentStore.h?rev=294309&r1=294308&r2=294309&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/DocumentStore.h (original)
+++ clang-tools-extra/trunk/clangd/DocumentStore.h Tue Feb  7 08:35:09 2017
@@ -26,7 +26,10 @@ public:
   /// Delete a document from the store.
   void removeDocument(StringRef Uri) { Docs.erase(Uri); }
   /// Retrieve a document from the store. Empty string if it's unknown.
-  StringRef getDocument(StringRef Uri) const { return Docs.lookup(Uri); }
+  StringRef getDocument(StringRef Uri) const {
+    auto I = Docs.find(Uri);
+    return I == Docs.end() ? StringRef("") : StringRef(I->second);
+  }
 
 private:
   llvm::StringMap<std::string> Docs;




More information about the cfe-commits mailing list