[clang-tools-extra] r353821 - [clangd] Fix use-after-free in XRefs
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 12 02:38:45 PST 2019
Author: sammccall
Date: Tue Feb 12 02:38:45 2019
New Revision: 353821
URL: http://llvm.org/viewvc/llvm-project?rev=353821&view=rev
Log:
[clangd] Fix use-after-free in XRefs
Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=353821&r1=353820&r2=353821&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Feb 12 02:38:45 2019
@@ -92,19 +92,18 @@ SymbolLocation toIndexLocation(const Loc
// Returns the preferred location between an AST location and an index location.
SymbolLocation getPreferredLocation(const Location &ASTLoc,
- const SymbolLocation &IdxLoc) {
+ const SymbolLocation &IdxLoc,
+ std::string &Scratch) {
// Also use a dummy symbol for the index location so that other fields (e.g.
// definition) are not factored into the preferrence.
Symbol ASTSym, IdxSym;
ASTSym.ID = IdxSym.ID = SymbolID("dummy_id");
- std::string URIStore;
- ASTSym.CanonicalDeclaration = toIndexLocation(ASTLoc, URIStore);
+ ASTSym.CanonicalDeclaration = toIndexLocation(ASTLoc, Scratch);
IdxSym.CanonicalDeclaration = IdxLoc;
auto Merged = mergeSymbol(ASTSym, IdxSym);
return Merged.CanonicalDeclaration;
}
-
struct MacroDecl {
llvm::StringRef Name;
const MacroInfo *Info;
@@ -352,6 +351,7 @@ std::vector<LocatedSymbol> locateSymbolA
LookupRequest QueryRequest;
for (auto It : ResultIndex)
QueryRequest.IDs.insert(It.first);
+ std::string Scratch;
Index->lookup(QueryRequest, [&](const Symbol &Sym) {
auto &R = Result[ResultIndex.lookup(Sym.ID)];
@@ -367,10 +367,10 @@ std::vector<LocatedSymbol> locateSymbolA
// Use merge logic to choose AST or index declaration.
// We only do this for declarations as definitions from AST
// is generally preferred (e.g. definitions in main file).
- if (auto Loc =
- toLSPLocation(getPreferredLocation(R.PreferredDeclaration,
- Sym.CanonicalDeclaration),
- *MainFilePath))
+ if (auto Loc = toLSPLocation(
+ getPreferredLocation(R.PreferredDeclaration,
+ Sym.CanonicalDeclaration, Scratch),
+ *MainFilePath))
R.PreferredDeclaration = *Loc;
}
}
More information about the cfe-commits
mailing list