Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

namespace Microsoft.Win32.SafeHandles
Expand All @@ -23,12 +24,12 @@ public SafeUnicodeStringHandle(string s)
public unsafe SafeUnicodeStringHandle(ReadOnlySpan<char> s)
: base(IntPtr.Zero, ownsHandle: true)
{
// If s == default then the span represents the null string,
// If s is null ref then the span represents the null string,
// and handle should be IntPtr.Zero to match Marshal.StringToHGlobalUni.
//
// Since that was already done in the base ctor call, we only need to do
// work when s != default.
if (s != default)
// work when s is not null ref.
if (!Unsafe.IsNullRef(ref MemoryMarshal.GetReference(s)))
{
int cch = checked(s.Length + 1);
int cb = checked(cch * sizeof(char));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace System.Security.Cryptography.Pkcs
Expand Down Expand Up @@ -115,9 +117,15 @@ private static void Derive(
// The password is a null-terminated UTF-16BE version of the input.
int passLen = checked((password.Length + 1) * 2);

// If password == default then the span represents the null string (as opposed to
// If password is null ref then the span represents the null string (as opposed to
// an empty string), and the P block should then have size 0 in the next step.
#if NETSTANDARD
#pragma warning disable CA2265 // Do not compare Span<T> to 'default'
if (password == default)
#pragma warning restore CA2265
#else
if (Unsafe.IsNullRef(ref MemoryMarshal.GetReference(password)))
#endif
{
passLen = 0;
}
Expand Down
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 System.Security;

Expand Down Expand Up @@ -35,8 +36,8 @@ public SafePasswordHandle(string? password, bool passwordProvided)
public SafePasswordHandle(ReadOnlySpan<char> password, bool passwordProvided)
: base(ownsHandle: true)
{
// "".AsSpan() is not default, so this is compat for "null tries NULL first".
if (password != default)
// "".AsSpan() is not null ref, so this is compat for "null tries NULL first".
if (!Unsafe.IsNullRef(ref MemoryMarshal.GetReference(password)))
{
int spanLen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Text.Json
{
Expand Down Expand Up @@ -1243,7 +1244,7 @@ public bool ValueEquals(ReadOnlySpan<byte> utf8Text)
if (TokenType == JsonTokenType.Null)
{
// This is different than Length == 0, in that it tests true for null, but false for ""
return utf8Text == default;
return Unsafe.IsNullRef(ref MemoryMarshal.GetReference(utf8Text));
}

return TextEqualsHelper(utf8Text, isPropertyName: false, shouldUnescape: true);
Expand Down Expand Up @@ -1271,7 +1272,7 @@ public bool ValueEquals(ReadOnlySpan<char> text)
if (TokenType == JsonTokenType.Null)
{
// This is different than Length == 0, in that it tests true for null, but false for ""
return text == default;
return Unsafe.IsNullRef(ref MemoryMarshal.GetReference(text));
}

return TextEqualsHelper(text, isPropertyName: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static bool TryFindCaseEquivalencesForCharWithIBehavior(char c, CultureIn
// Default
_ => default
};
return equivalences != default;
return !equivalences.IsEmpty;
}
else
{
Expand Down