Skip to content

Commit dbd40e5

Browse files
committed
Use [SkipLocalsInit] for stackalloc.
1 parent f8c029b commit dbd40e5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/MySqlConnector/Core/Row.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Buffers.Text;
2+
using System.Runtime.CompilerServices;
23
using System.Runtime.InteropServices;
34
using System.Text;
45
using MySqlConnector.Protocol;
@@ -555,6 +556,9 @@ protected object ParseDateTime(ReadOnlySpan<byte> value)
555556
throw new FormatException("Couldn't interpret '{0}' as a valid DateTime".FormatInvariant(Encoding.UTF8.GetString(value)), exception);
556557
}
557558

559+
#if NET5_0_OR_GREATER
560+
[SkipLocalsInit]
561+
#endif
558562
protected static unsafe Guid CreateGuidFromBytes(MySqlGuidFormat guidFormat, ReadOnlySpan<byte> bytes) =>
559563
guidFormat switch
560564
{

src/MySqlConnector/Protocol/Serialization/AuthenticationUtility.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.CompilerServices;
12
using System.Security.Cryptography;
23
using System.Text;
34
using MySqlConnector.Utilities;
@@ -16,6 +17,9 @@ public static byte[] CreateAuthenticationResponse(ReadOnlySpan<byte> challenge,
1617
/// <param name="password">The password to hash.</param>
1718
/// <returns>A 20-byte password hash.</returns>
1819
/// <remarks>See <a href="https://dev.mysql.com/doc/internals/en/secure-password-authentication.html">Secure Password Authentication</a>.</remarks>
20+
#if NET5_0_OR_GREATER
21+
[SkipLocalsInit]
22+
#endif
1923
public static byte[] HashPassword(ReadOnlySpan<byte> challenge, string password)
2024
{
2125
using var sha1 = SHA1.Create();
@@ -46,6 +50,9 @@ public static byte[] CreateScrambleResponse(ReadOnlySpan<byte> nonce, string pas
4650
return scrambleResponse;
4751
}
4852

53+
#if NET5_0_OR_GREATER
54+
[SkipLocalsInit]
55+
#endif
4956
private static byte[] HashPasswordWithNonce(ReadOnlySpan<byte> nonce, string password)
5057
{
5158
using var sha256 = SHA256.Create();

0 commit comments

Comments
 (0)