dotnet / dotnet/csharpstandard

23.8.3 PutString example may not null-terminate

Open
#140 3 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

The final example in 24.8.3 includes:

``` csharp
unsafe static void PutString(string s, char* buffer, int bufSize) {
int len = s.Length;
if (len > bufSize) len = bufSize;
for (int i = 0; i < len; i++) buffer[i] = s[i];
for (int i = len; i < bufSize; i++) buffer[i] = (char)0;
}
```

If `len == bufSize`, this will write all those chars but not null-terminate. Other code we have in the standard appears to expect a null-terminated string. What should we do here? Only write `bufSize - 1` characters, then `'\0'`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.