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))
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))
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits