pinvoke icon indicating copy to clipboard operation
pinvoke copied to clipboard

Ensure `ReadOnlySpan<char>` where null-terminated element is required is done right

Open AArnott opened this issue 5 years ago • 0 comments

#535 introduces a ReadOnlySpan<char> overload for CreateFile. The use of span suggests to the caller that length is taken into account, but it is not. Instead, CreateFile is only going to get the pointer and will read till it encounters a UTF-16 null character. To help avoid calls that are missing a null character from badly misbehaving, should we:

  1. rely on documentation on the parameter?
  2. enhance the code generated overload with ReadOnlySpan<char> to check and throw if the last element in the span is not a null character?

AArnott avatar Oct 27 '20 15:10 AArnott