Fix comparison of value type object to null (#13285)

This commit is contained in:
xtqqczze
2020-08-10 14:56:14 -07:00
committed by GitHub
parent b430303a03
commit d8f8f0a8bc
11 changed files with 12 additions and 13 deletions
@@ -462,7 +462,7 @@ namespace Microsoft.Powershell.Commands.GetCounter.PdhNative
defaultScale = 0;
timeBase = 0;
Debug.Assert(hCounter != null);
Debug.Assert(hCounter != IntPtr.Zero);
IntPtr pBufferSize = new IntPtr(0);
res = PdhGetCounterInfo(hCounter, false, ref pBufferSize, IntPtr.Zero);
@@ -1190,7 +1190,7 @@ namespace Microsoft.Powershell.Commands.GetCounter.PdhNative
UInt64 timeBase = 0;
IntPtr hCounter = _consumerPathToHandleAndInstanceMap[path].hCounter;
Debug.Assert(hCounter != null);
Debug.Assert(hCounter != IntPtr.Zero);
res = GetCounterInfoPlus(hCounter, out counterType, out defaultScale, out timeBase);
if (res != 0)
@@ -1915,7 +1915,7 @@ namespace Microsoft.PowerShell.Commands
InvocationInfo invocationInfo)
{
Dbg.Assert(remoteRunspaceInfo != null, "Caller should validate remoteRunspaceInfo != null");
Dbg.Assert(moduleGuid != null, "Caller should validate moduleGuid != null");
Dbg.Assert(moduleGuid != Guid.Empty, "Caller should validate moduleGuid is not empty");
Dbg.Assert(invocationInfo != null, "Caller should validate invocationInfo != null");
_remoteRunspaceInfo = remoteRunspaceInfo;
@@ -1206,7 +1206,6 @@ namespace Microsoft.PowerShell
if (!_isDisposed)
{
#if !UNIX
Dbg.Assert(breakHandlerGcHandle != null, "break handler should be set");
ConsoleControl.RemoveBreakHandler();
if (breakHandlerGcHandle.IsAllocated)
{
@@ -204,7 +204,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
int cols = _si.columnInfo.Length;
Span<int> currentAlignment = cols <= OutCommandInner.StackAllocThreshold ? stackalloc int[cols] : new int[cols];
if (alignment == null)
if (alignment.IsEmpty)
{
for (int i = 0; i < currentAlignment.Length; i++)
{
@@ -111,9 +111,9 @@ namespace System.Management.Automation.Runspaces.Internal
ConnectCommandInfo[] connectCommands, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
: base(1, 1)
{
if (instanceId == null)
if (instanceId == Guid.Empty)
{
throw PSTraceSource.NewArgumentNullException("RunspacePool Guid");
throw PSTraceSource.NewArgumentException(nameof(instanceId));
}
if (connectCommands == null)
@@ -318,7 +318,7 @@ namespace System.Management.Automation.Remoting
private void CleanUpDelegates()
{
// Free GCHandles so that the memory they point to may be unpinned (garbage collected)
if (_pluginShellGCHandle != null)
if (_pluginShellGCHandle.IsAllocated)
{
_pluginShellGCHandle.Free();
_pluginReleaseShellContextGCHandle.Free();
@@ -2280,7 +2280,7 @@ namespace System.Management.Automation.Remoting.Client
}
// process returned Xml
Dbg.Assert(data != null, "WSManConnectShell callback returned null data");
Dbg.Assert(data != IntPtr.Zero, "WSManConnectShell callback returned null data");
WSManNativeApi.WSManConnectDataResult connectData = WSManNativeApi.WSManConnectDataResult.UnMarshal(data);
if (connectData.data != null)
{
@@ -152,7 +152,7 @@ namespace System.Management.Automation.Internal
private void CleanUpDelegates()
{
// Free GCHandles so that the memory they point to may be unpinned (garbage collected)
if (_fdiAllocHandle != null)
if (_fdiAllocHandle.IsAllocated)
{
_fdiAllocHandle.Free();
_fdiFreeHandle.Free();
@@ -28,7 +28,7 @@ namespace System.Management.Automation.Help
internal UpdatableHelpModuleInfo(string name, Guid guid, string path, string uri)
{
Debug.Assert(!string.IsNullOrEmpty(name));
Debug.Assert(guid != null);
Debug.Assert(guid != Guid.Empty);
Debug.Assert(!string.IsNullOrEmpty(path));
Debug.Assert(!string.IsNullOrEmpty(uri));
@@ -21,7 +21,7 @@ namespace System.Management.Automation.Help
internal UpdatableHelpUri(string moduleName, Guid moduleGuid, CultureInfo culture, string resolvedUri)
{
Debug.Assert(!string.IsNullOrEmpty(moduleName));
Debug.Assert(moduleGuid != null);
Debug.Assert(moduleGuid != Guid.Empty);
Debug.Assert(!string.IsNullOrEmpty(resolvedUri));
ModuleName = moduleName;
@@ -192,7 +192,7 @@ namespace System.Management.Automation
IntPtr.Zero);
#pragma warning restore 56523
if (si.pSignExtInfo != null)
if (si.pSignExtInfo != IntPtr.Zero)
{
Marshal.DestroyStructure<NativeMethods.CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO>(si.pSignExtInfo);
Marshal.FreeCoTaskMem(si.pSignExtInfo);