Skip to content

Commit

Permalink
Use Unsafe.NullRef (#79589)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze authored Dec 19, 2022
1 parent a92c5bc commit fc65281
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

Expand Down Expand Up @@ -115,8 +116,12 @@ ref MemoryMarshal.GetReference(input),

internal static void EvpCipherSetInputLength(SafeEvpCipherCtxHandle ctx, int inputLength)
{
ref byte nullRef = ref MemoryMarshal.GetReference(Span<byte>.Empty);
if (!EvpCipherUpdate(ctx, ref nullRef, out _, ref nullRef, inputLength))
if (!EvpCipherUpdate(
ctx,
ref Unsafe.NullRef<byte>(),
out _,
ref Unsafe.NullRef<byte>(),
inputLength))
{
throw CreateOpenSslCryptographicException();
}
Expand Down Expand Up @@ -229,8 +234,7 @@ internal static void EvpCipherSetCcmTag(SafeEvpCipherCtxHandle ctx, ReadOnlySpan

internal static void EvpCipherSetCcmTagLength(SafeEvpCipherCtxHandle ctx, int tagLength)
{
ref byte nullRef = ref MemoryMarshal.GetReference(Span<byte>.Empty);
if (!EvpCipherSetCcmTag(ctx, ref nullRef, tagLength))
if (!EvpCipherSetCcmTag(ctx, ref Unsafe.NullRef<byte>(), tagLength))
{
throw CreateOpenSslCryptographicException();
}
Expand Down

0 comments on commit fc65281

Please sign in to comment.