forked from OSchip/llvm-project
[clangd][Dex] Fix crashes when building trigrams for empty identifier
This commit is contained in:
parent
6c85a49e22
commit
a47af1ac34
|
@ -28,6 +28,7 @@ namespace dex {
|
||||||
// Produce trigrams (including duplicates) and pass them to Out().
|
// Produce trigrams (including duplicates) and pass them to Out().
|
||||||
template <typename Func>
|
template <typename Func>
|
||||||
static void identifierTrigrams(llvm::StringRef Identifier, Func Out) {
|
static void identifierTrigrams(llvm::StringRef Identifier, Func Out) {
|
||||||
|
assert(!Identifier.empty());
|
||||||
// Apply fuzzy matching text segmentation.
|
// Apply fuzzy matching text segmentation.
|
||||||
llvm::SmallVector<CharRole> Roles(Identifier.size());
|
llvm::SmallVector<CharRole> Roles(Identifier.size());
|
||||||
calculateRoles(Identifier,
|
calculateRoles(Identifier,
|
||||||
|
@ -104,6 +105,9 @@ void generateIdentifierTrigrams(llvm::StringRef Identifier,
|
||||||
// The magic number was tuned by running IndexBenchmark.DexBuild.
|
// The magic number was tuned by running IndexBenchmark.DexBuild.
|
||||||
constexpr unsigned ManyTrigramsIdentifierThreshold = 14;
|
constexpr unsigned ManyTrigramsIdentifierThreshold = 14;
|
||||||
Result.clear();
|
Result.clear();
|
||||||
|
if (Identifier.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
if (Identifier.size() < ManyTrigramsIdentifierThreshold) {
|
if (Identifier.size() < ManyTrigramsIdentifierThreshold) {
|
||||||
identifierTrigrams(Identifier, [&](Trigram T) {
|
identifierTrigrams(Identifier, [&](Trigram T) {
|
||||||
if (!llvm::is_contained(Result, T))
|
if (!llvm::is_contained(Result, T))
|
||||||
|
|
|
@ -415,6 +415,7 @@ TEST(DexTrigrams, IdentifierTrigrams) {
|
||||||
"cdg", "def", "deg", "dgh", "dgk", "efg", "egh",
|
"cdg", "def", "deg", "dgh", "dgk", "efg", "egh",
|
||||||
"egk", "fgh", "fgk", "ghi", "ghk", "gkl", "hij",
|
"egk", "fgh", "fgk", "ghi", "ghk", "gkl", "hij",
|
||||||
"hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
|
"hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
|
||||||
|
EXPECT_THAT(identifierTrigramTokens(""), IsEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DexTrigrams, QueryTrigrams) {
|
TEST(DexTrigrams, QueryTrigrams) {
|
||||||
|
|
Loading…
Reference in New Issue