[PATCH] D92646: [Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 4 12:55:24 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG650e04e179c9: [Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it. (authored by sammccall).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92646/new/
https://reviews.llvm.org/D92646
Files:
clang/lib/Tooling/JSONCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp
Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -172,13 +172,15 @@
}
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
- StringRef JSONDatabase,
+ std::string JSONDatabase,
std::string &ErrorMessage) {
std::unique_ptr<CompilationDatabase> Database(
JSONCompilationDatabase::loadFromBuffer(JSONDatabase, ErrorMessage,
JSONCommandLineSyntax::Gnu));
if (!Database)
return CompileCommand();
+ // Overwrite the string to verify we're not reading from it later.
+ JSONDatabase.assign(JSONDatabase.size(), '*');
std::vector<CompileCommand> Commands = Database->getCompileCommands(FileName);
EXPECT_LE(Commands.size(), 1u);
if (Commands.empty())
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===================================================================
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -217,7 +217,7 @@
std::string &ErrorMessage,
JSONCommandLineSyntax Syntax) {
std::unique_ptr<llvm::MemoryBuffer> DatabaseBuffer(
- llvm::MemoryBuffer::getMemBuffer(DatabaseString));
+ llvm::MemoryBuffer::getMemBufferCopy(DatabaseString));
std::unique_ptr<JSONCompilationDatabase> Database(
new JSONCompilationDatabase(std::move(DatabaseBuffer), Syntax));
if (!Database->parse(ErrorMessage))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92646.309626.patch
Type: text/x-patch
Size: 1811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201204/a9092da5/attachment.bin>
More information about the cfe-commits
mailing list