dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

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

Closed AArnott closed 1 year ago

AArnott commented 3 years ago

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?