diff options
author | macurtis-amd <macurtis@amd.com> | 2024-12-13 05:27:00 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-13 05:27:00 -0600 |
commit | 8bf19ec444593b3076a446a8eeb5042bbf79dc65 (patch) | |
tree | 87f7b0477fc17a261cfed27cea0f4285079dc570 /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | 84b0f0145887bbfe49fd4dc85490b14108a72cee (diff) | |
download | llvm-8bf19ec444593b3076a446a8eeb5042bbf79dc65.zip llvm-8bf19ec444593b3076a446a8eeb5042bbf79dc65.tar.gz llvm-8bf19ec444593b3076a446a8eeb5042bbf79dc65.tar.bz2 |
[clang] Fix use of dangling ptr in CommandLineTest (#119798)
If 'GeneratedArgsStorage' ever grows, contained strings may get copied
and data pointers stored in 'GeneratedArgs' may become invalid, pointing
to deallocated memory.
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 4ff6824..94ab9fe 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -31,17 +31,19 @@ class CommandLineTest : public ::testing::Test { public: IntrusiveRefCntPtr<DiagnosticsEngine> Diags; SmallVector<const char *, 32> GeneratedArgs; - SmallVector<std::string, 32> GeneratedArgsStorage; + BumpPtrAllocator Alloc; + StringSaver StringPool; CompilerInvocation Invocation; const char *operator()(const Twine &Arg) { - return GeneratedArgsStorage.emplace_back(Arg.str()).c_str(); + return StringPool.save(Arg).data(); } CommandLineTest() : Diags(CompilerInstance::createDiagnostics( *llvm::vfs::getRealFileSystem(), new DiagnosticOptions(), - new TextDiagnosticBuffer())) {} + new TextDiagnosticBuffer())), + StringPool(Alloc) {} }; template <typename M> |