[Xamarin.MacDev] Use Stream.ReadExactly instead of Stream.Read when we can. (#121)

Fixes these warnings:

    Xamarin.MacDev/PListObject.cs(1353,7): warning CA2022: Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
    Xamarin.MacDev/PListObject.cs(1357,7): warning CA2022: Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
    Xamarin.MacDev/PListObject.cs(1343,6): warning CA2022: Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
    Xamarin.MacDev/PListObject.cs(1421,6): warning CA2022: Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
This commit is contained in:
Rolf Bjarne Kvinge 2024-04-22 19:07:25 +02:00 коммит произвёл GitHub
Родитель e707772e17
Коммит 4cb9dc2632
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -1340,7 +1340,11 @@ namespace Xamarin.MacDev {
protected override byte [] ReadData ()
{
var bytes = new byte [currentLength];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, currentLength);
#else
stream.Read (bytes, 0, currentLength);
#endif
return bytes;
}
@ -1350,11 +1354,19 @@ namespace Xamarin.MacDev {
switch (CurrentType) {
case PlistType.@string: // ASCII
bytes = new byte [currentLength];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, bytes.Length);
#else
stream.Read (bytes, 0, bytes.Length);
#endif
return Encoding.ASCII.GetString (bytes);
case PlistType.wideString: //CFBinaryPList.c: Unicode string...big-endian 2-byte uint16_t
bytes = new byte [currentLength * 2];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, bytes.Length);
#else
stream.Read (bytes, 0, bytes.Length);
#endif
return Encoding.BigEndianUnicode.GetString (bytes);
}
@ -1418,7 +1430,11 @@ namespace Xamarin.MacDev {
byte [] ReadBigEndianBytes (int count)
{
var bytes = new byte [count];
#if NET7_0_OR_GREATER
stream.ReadExactly (bytes, 0, count);
#else
stream.Read (bytes, 0, count);
#endif
if (BitConverter.IsLittleEndian)
Array.Reverse (bytes);
return bytes;