Skip to content

Commit

Permalink
[Xamarin.MacDev] Use Stream.ReadExactly instead of Stream.Read when w…
Browse files Browse the repository at this point in the history
…e 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)
  • Loading branch information
rolfbjarne authored Apr 22, 2024
1 parent e707772 commit 4cb9dc2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Xamarin.MacDev/PListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,11 @@ protected override DateTime ReadDate ()
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;
}

Expand All @@ -1350,11 +1354,19 @@ protected override string ReadString ()
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);
}

Expand Down Expand Up @@ -1418,7 +1430,11 @@ public override bool ReadDict (PDictionary dict)
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;
Expand Down

0 comments on commit 4cb9dc2

Please sign in to comment.