[clang] [Format] Do not crash on non-null terminated strings (PR #131299)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 18 11:14:11 PDT 2025
================
@@ -2382,14 +2382,20 @@ size_t SourceManager::getDataStructureSizes() const {
SourceManagerForFile::SourceManagerForFile(StringRef FileName,
StringRef Content) {
+ // We copy to `std::string` for Context instead of StringRef because the
+ // SourceManager::getBufferData() works only with null-terminated buffers.
+ // And we still want to keep the API convenient.
+ ContentBuffer = Content.str();
----------------
ilya-biryukov wrote:
Is there any particular direction folks want to take this?
Having an API that breaks on non-null-terminated `StringRef` looks but and I don't see **easy** options to fix this other than a copy.
I don't expect this to give any noticeable performance regressions, and I don't have a clear sense of whether the folks in the comment threads agree or disagree.
https://github.com/llvm/llvm-project/pull/131299
More information about the cfe-commits
mailing list