[lld] r183603 - [WinLink] Fix use-after-return.
Rui Ueyama
ruiu at google.com
Fri Jun 7 20:39:36 PDT 2013
Author: ruiu
Date: Fri Jun 7 22:39:35 2013
New Revision: 183603
URL: http://llvm.org/viewvc/llvm-project?rev=183603&view=rev
Log:
[WinLink] Fix use-after-return.
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h?rev=183603&r1=183602&r2=183603&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h Fri Jun 7 22:39:35 2013
@@ -14,6 +14,7 @@
#include "lld/ReaderWriter/Reader.h"
#include "lld/ReaderWriter/Writer.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/ErrorHandling.h"
@@ -59,12 +60,20 @@ public:
return _minOSVersion;
}
+ StringRef allocateString(const StringRef &ref) {
+ char *x = _extraStrings.Allocate<char>(ref.size() + 1);
+ memcpy(x, ref.data(), ref.size());
+ x[ref.size()] = '\0';
+ return x;
+ }
+
private:
llvm::COFF::WindowsSubsystem _subsystem;
OSVersion _minOSVersion;
mutable std::unique_ptr<Reader> _reader;
mutable std::unique_ptr<Writer> _writer;
+ llvm::BumpPtrAllocator _extraStrings;
};
} // end namespace lld
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=183603&r1=183602&r2=183603&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Jun 7 22:39:35 2013
@@ -127,19 +127,19 @@ bool parseSubsystemOption(PECOFFTargetIn
}
// Add ".obj" extension if the given path name has no file extension.
-std::string canonicalizeInputFileName(std::string path) {
+StringRef canonicalizeInputFileName(PECOFFTargetInfo &info, std::string path) {
if (llvm::sys::path::extension(path).empty())
- return path.append(".obj");
- return path;
+ path.append(".obj");
+ return info.allocateString(path);
}
// Replace a file extension with ".exe". If the given file has no
// extension, just add ".exe".
-std::string getDefaultOutputFileName(std::string path) {
+StringRef getDefaultOutputFileName(PECOFFTargetInfo &info, std::string path) {
StringRef ext = llvm::sys::path::extension(path);
if (!ext.empty())
path.erase(path.size() - ext.size());
- return path.append(".exe");
+ return info.allocateString(path.append(".exe"));
}
} // namespace
@@ -223,12 +223,12 @@ bool WinLinkDriver::parse(int argc, cons
// Add ".obj" extension for those who have no file extension.
for (const StringRef &path : inputPaths)
- info.appendInputFile(canonicalizeInputFileName(path));
+ info.appendInputFile(canonicalizeInputFileName(info, path));
// If -out option was not specified, the default output file name is
// constructed by replacing an extension with ".exe".
if (info.outputPath().empty() && !inputPaths.empty())
- info.setOutputPath(getDefaultOutputFileName(inputPaths[0]));
+ info.setOutputPath(getDefaultOutputFileName(info, inputPaths[0]));
// Validate the combination of options used.
return info.validate(diagnostics);
More information about the llvm-commits
mailing list