[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:03:19 PDT 2025


================
@@ -29096,6 +29096,17 @@ TEST_F(FormatTest, BreakBeforeClassName) {
                "    ArenaSafeUniquePtr {};");
 }
 
+TEST_F(FormatTest, DoesNotCrashOnNonNullTerminatedStringRefs) {
+  llvm::StringRef TwoLines = "namespace foo {}\n"
+                             "namespace bar {}";
+  llvm::StringRef FirstLine =
+      TwoLines.take_until([](char c) { return c == '\n'; });
+
+  // The internal API used to crash when passed a non-null-terminated StringRef.
+  // Check this does not happen anymore.
+  verifyFormat(FirstLine);
----------------
ilya-biryukov wrote:

Using it now, thanks.

https://github.com/llvm/llvm-project/pull/131299


More information about the cfe-commits mailing list