[clang-tools-extra] r322949 - [clangd] Fix memcpy(?, null, 0) UB by switching to std::copy
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 19 07:03:49 PST 2018
Author: sammccall
Date: Fri Jan 19 07:03:49 2018
New Revision: 322949
URL: http://llvm.org/viewvc/llvm-project?rev=322949&view=rev
Log:
[clangd] Fix memcpy(?, null, 0) UB by switching to std::copy
Modified:
clang-tools-extra/trunk/clangd/FuzzyMatch.cpp
Modified: clang-tools-extra/trunk/clangd/FuzzyMatch.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FuzzyMatch.cpp?rev=322949&r1=322948&r2=322949&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/FuzzyMatch.cpp (original)
+++ clang-tools-extra/trunk/clangd/FuzzyMatch.cpp Fri Jan 19 07:03:49 2018
@@ -76,7 +76,7 @@ static constexpr int PerfectBonus = 3; /
FuzzyMatcher::FuzzyMatcher(StringRef Pattern)
: PatN(std::min<int>(MaxPat, Pattern.size())), CaseSensitive(false),
ScoreScale(PatN ? float{1} / (PerfectBonus * PatN) : 0), WordN(0) {
- memcpy(Pat, Pattern.data(), PatN);
+ std::copy(Pattern.begin(), Pattern.begin() + PatN, Pat);
for (int I = 0; I < PatN; ++I) {
LowPat[I] = lower(Pat[I]);
CaseSensitive |= LowPat[I] != Pat[I];
@@ -200,7 +200,7 @@ bool FuzzyMatcher::init(StringRef NewWor
WordN = std::min<int>(MaxWord, NewWord.size());
if (PatN > WordN)
return false;
- memcpy(Word, NewWord.data(), WordN);
+ std::copy(NewWord.begin(), NewWord.begin() + WordN, Word);
if (PatN == 0)
return true;
for (int I = 0; I < WordN; ++I)
More information about the cfe-commits
mailing list