From d8f8f0a8bcbadb357f9eaafbb797278ebe07d7cc Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 10 Aug 2020 22:56:14 +0100 Subject: [PATCH] Fix comparison of value type object to null (#13285) --- src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs | 4 ++-- .../commands/utility/ImplicitRemotingCommands.cs | 2 +- src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs | 1 - .../FormatAndOutput/common/TableWriter.cs | 2 +- .../engine/remoting/client/RemoteRunspacePoolInternal.cs | 4 ++-- .../engine/remoting/fanin/WSManPluginFacade.cs | 2 +- .../engine/remoting/fanin/WSManTransportManager.cs | 2 +- src/System.Management.Automation/help/CabinetNativeApi.cs | 2 +- .../help/UpdatableHelpModuleInfo.cs | 2 +- src/System.Management.Automation/help/UpdatableHelpUri.cs | 2 +- src/System.Management.Automation/security/Authenticode.cs | 2 +- 11 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs index e535535d25..130a7f4180 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs @@ -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) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index 58d9d762ab..feeb0cd091 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -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; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 39a32d77c2..206a7e44e7 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -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) { diff --git a/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs b/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs index e01be6f5b8..54aaa9438c 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs @@ -204,7 +204,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format int cols = _si.columnInfo.Length; Span currentAlignment = cols <= OutCommandInner.StackAllocThreshold ? stackalloc int[cols] : new int[cols]; - if (alignment == null) + if (alignment.IsEmpty) { for (int i = 0; i < currentAlignment.Length; i++) { diff --git a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs index 7c2aceec7d..17b07b0f14 100644 --- a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs @@ -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) diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs index ed5bf0a4a3..31f0e0d268 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs @@ -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(); diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs index 1fad7ccb3e..92cb98664e 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs @@ -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) { diff --git a/src/System.Management.Automation/help/CabinetNativeApi.cs b/src/System.Management.Automation/help/CabinetNativeApi.cs index 4b19861e47..833ed6506f 100644 --- a/src/System.Management.Automation/help/CabinetNativeApi.cs +++ b/src/System.Management.Automation/help/CabinetNativeApi.cs @@ -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(); diff --git a/src/System.Management.Automation/help/UpdatableHelpModuleInfo.cs b/src/System.Management.Automation/help/UpdatableHelpModuleInfo.cs index 9f0c32d679..6da6c256dc 100644 --- a/src/System.Management.Automation/help/UpdatableHelpModuleInfo.cs +++ b/src/System.Management.Automation/help/UpdatableHelpModuleInfo.cs @@ -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)); diff --git a/src/System.Management.Automation/help/UpdatableHelpUri.cs b/src/System.Management.Automation/help/UpdatableHelpUri.cs index 28683a3e2a..8b854e82a5 100644 --- a/src/System.Management.Automation/help/UpdatableHelpUri.cs +++ b/src/System.Management.Automation/help/UpdatableHelpUri.cs @@ -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; diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index cf5e559f83..0abdafa956 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -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(si.pSignExtInfo); Marshal.FreeCoTaskMem(si.pSignExtInfo);