The number of bytes or characters a Read call returns is ignored
What it finds
stream.Read(buffer, 0, buffer.Length) may read fewer bytes than asked for, and says how many it read in its result. Ignoring it treats the rest of the buffer as data. Loop until done, or use ReadExactly.
From the rule's source, ignored_read_count.rs.
using System.IO;using System.Threading.Tasks; class Reader{ async Task Load(Stream stream, byte[] buffer) { stream.Read(buffer, 0, buffer.Length);tx0 reports: the count that Read returns is ignored; it may read less than asked for await stream.ReadAsync(buffer, 0, 16).ConfigureAwait(false);tx0 reports: the count that ReadAsync returns is ignored; it may read less than asked for var n = stream.Read(buffer, 0, buffer.Length); stream.ReadExactly(buffer, 0, 4); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:ignored-read-count" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:ignored-read-count] reason="..."tx0 explain tx0/csharp:ignored-read-count shows the same in the terminal. Found a false positive? Report it.