1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

Fix stack-use-after free after r359580

`Candidate` was a StringRef refering to a temporary string.
Instead, create a local variable for the string and use
a StringRef referring to that.

llvm-svn: 359604
This commit is contained in:
Nico Weber 2019-04-30 19:43:35 +00:00
parent 37ab5fb9f1
commit bad7b97678

View File

@ -296,10 +296,11 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
// "--help" over "-help". // "--help" over "-help".
for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) { for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
std::string NormalizedName = (LHS + Delimiter).str(); std::string NormalizedName = (LHS + Delimiter).str();
StringRef Candidate = (CandidatePrefix + CandidateName).str(); std::string Candidate = (CandidatePrefix + CandidateName).str();
StringRef CandidateRef = Candidate;
unsigned Distance = unsigned Distance =
Candidate.edit_distance(NormalizedName, /*AllowReplacements=*/true, CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true,
/*MaxEditDistance=*/BestDistance); /*MaxEditDistance=*/BestDistance);
if (Distance < BestDistance) { if (Distance < BestDistance) {
BestDistance = Distance; BestDistance = Distance;
NearestString = (Candidate + RHS).str(); NearestString = (Candidate + RHS).str();