summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-04-30 19:43:35 +0000
committerNico Weber <nicolasweber@gmx.de>2019-04-30 19:43:35 +0000
commite7fa09e4ae8ae50419010cac056637733e297c8c (patch)
tree9ebdf5732968ecdac9047cc66e71faa56479e736 /llvm/lib/Option/OptTable.cpp
parentb4989294c8199814ad04e83e6fd703772b8f78cb (diff)
downloadbcm5719-llvm-e7fa09e4ae8ae50419010cac056637733e297c8c.tar.gz
bcm5719-llvm-e7fa09e4ae8ae50419010cac056637733e297c8c.zip
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
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 8956c6830db..1585059c2fb 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -296,10 +296,11 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
// "--help" over "-help".
for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
std::string NormalizedName = (LHS + Delimiter).str();
- StringRef Candidate = (CandidatePrefix + CandidateName).str();
+ std::string Candidate = (CandidatePrefix + CandidateName).str();
+ StringRef CandidateRef = Candidate;
unsigned Distance =
- Candidate.edit_distance(NormalizedName, /*AllowReplacements=*/true,
- /*MaxEditDistance=*/BestDistance);
+ CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true,
+ /*MaxEditDistance=*/BestDistance);
if (Distance < BestDistance) {
BestDistance = Distance;
NearestString = (Candidate + RHS).str();
OpenPOWER on IntegriCloud