Skip to content

Commit

Permalink
Merge pull request #1429 from SteamRE/fix-CA2022
Browse files Browse the repository at this point in the history
Fix CA2022 warnings ahead of .NET 9
  • Loading branch information
xPaw authored Sep 14, 2024
2 parents b4e4cb9 + 3183100 commit 35f32bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions SteamKit2/SteamKit2/Util/StreamHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,55 @@ public static short ReadInt16(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(Int16)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToInt16( data );
}

public static ushort ReadUInt16(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(UInt16)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToUInt16( data );
}

public static int ReadInt32(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(Int32)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToInt32( data );
}

public static long ReadInt64(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(Int64)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToInt64( data );
}

public static uint ReadUInt32(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(UInt32)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToUInt32( data );
}

public static ulong ReadUInt64(this Stream stream)
{
Span<byte> data = stackalloc byte[sizeof(UInt64)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToUInt64( data );
}

public static float ReadFloat( this Stream stream )
{
Span<byte> data = stackalloc byte[sizeof(float)];

stream.Read( data );
stream.ReadExactly( data );
return BitConverter.ToSingle( data );
}

Expand All @@ -80,9 +80,10 @@ public static string ReadNullTermString( this Stream stream, Encoding encoding )
while ( true )
{
data.Clear();
stream.Read( data );

if ( encoding.GetString( data ) == NullTerminator )
var bytesRead = stream.ReadAtLeast( data, data.Length, throwOnEndOfStream: false );

if ( bytesRead == 0 || encoding.GetString( data ) == NullTerminator )
{
break;
}
Expand Down
2 changes: 1 addition & 1 deletion SteamKit2/Tests/StreamHelpersFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ThreadStart(object o)
var threadNumber = (int)o;

using var ms = new MemoryStream();
var bytes = BitConverter.GetBytes( threadNumber );
var bytes = BitConverter.GetBytes( ( long )threadNumber );
ms.Write( bytes, 0, bytes.Length );

for ( var i = 0; i < 1000; i++ )
Expand Down

0 comments on commit 35f32bc

Please sign in to comment.