Skip to content

Commit a5e6967

Browse files
Add a note about our guaranteed string.Create behavior (#109380)
1 parent 1b27ee9 commit a5e6967

File tree

1 file changed

+4
-0
lines changed
  • src/libraries/System.Private.CoreLib/src/System

1 file changed

+4
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/String.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ private static unsafe string Ctor(ReadOnlySpan<char> value)
322322
public static string Create<TState>(int length, TState state, SpanAction<char, TState> action)
323323
where TState : allows ref struct
324324
{
325+
// To support interop scenarios, the underlying buffer is guaranteed to be at least 1 greater than represented by the span parameter of the action callback.
326+
// This additional index represents the null-terminator and, if written, that is the only value supported.
327+
// Writing any value other than the null-terminator corrupts the string and is considered undefined behavior.
328+
325329
if (action is null)
326330
{
327331
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);

0 commit comments

Comments
 (0)