[lld] r240183 - COFF: Take reference to argument vector using std::vector::data() instead of operator[](0).
Peter Collingbourne
peter at pcc.me.uk
Fri Jun 19 15:40:05 PDT 2015
Author: pcc
Date: Fri Jun 19 17:40:05 2015
New Revision: 240183
URL: http://llvm.org/viewvc/llvm-project?rev=240183&view=rev
Log:
COFF: Take reference to argument vector using std::vector::data() instead of operator[](0).
This avoids undefined behaviour caused by an out-of-range access if the
vector is empty, which can happen if an object file's directive section
contains only whitespace.
Modified:
lld/trunk/COFF/DriverUtils.cpp
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=240183&r1=240182&r2=240183&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Fri Jun 19 17:40:05 2015
@@ -557,7 +557,7 @@ ArgParser::parse(std::vector<const char
unsigned MissingIndex;
unsigned MissingCount;
std::unique_ptr<llvm::opt::InputArgList> Args(Table.ParseArgs(
- &Argv[0], &Argv[0] + Argv.size(), MissingIndex, MissingCount));
+ Argv.data(), Argv.data() + Argv.size(), MissingIndex, MissingCount));
if (MissingCount) {
llvm::errs() << "missing arg value for \""
<< Args->getArgString(MissingIndex)
@@ -587,7 +587,7 @@ std::vector<const char *> ArgParser::tok
// character. '@<filename>' is replaced by the file's contents.
ErrorOr<std::vector<const char *>>
ArgParser::replaceResponseFiles(std::vector<const char *> Argv) {
- SmallVector<const char *, 256> Tokens(&Argv[0], &Argv[0] + Argv.size());
+ SmallVector<const char *, 256> Tokens(Argv.data(), Argv.data() + Argv.size());
BumpPtrStringSaver Saver(AllocAux);
ExpandResponseFiles(Saver, TokenizeWindowsCommandLine, Tokens);
return std::vector<const char *>(Tokens.begin(), Tokens.end());
More information about the llvm-commits
mailing list