From b829325d8d3016242942f58c5da4293698fdc549 Mon Sep 17 00:00:00 2001 From: "v.glagolev" Date: Sun, 15 Oct 2017 21:53:46 +0300 Subject: [PATCH 1/2] Multiple improvements by CodeRush Static Analysis --- .../commands/management/GetChildrenCommand.cs | 3 +- .../commands/management/Navigation.cs | 7 +-- .../commands/management/SetContentCommand.cs | 3 +- .../host/msh/ConsoleHostRawUserInterface.cs | 6 +-- .../Eventing/Reader/EventLogReader.cs | 11 +--- src/Microsoft.PowerShell.PSReadLine/Words.cs | 51 ++++--------------- .../ConfigProvider.cs | 2 +- src/Microsoft.WSMan.Management/WsManHelper.cs | 14 ++--- .../CommandCompletion/CommandCompletion.cs | 5 +- .../engine/CoreAdapter.cs | 7 +-- .../engine/DataStoreAdapter.cs | 13 ++--- .../engine/DataStoreAdapterProvider.cs | 6 +-- .../engine/LanguagePrimitives.cs | 2 +- .../engine/Modules/AnalysisCache.cs | 4 +- .../engine/SessionStatePublic.cs | 4 +- .../engine/hostifaces/PowerShell.cs | 6 +-- .../engine/interpreter/CallInstruction.cs | 2 +- .../interpreter/ControlFlowInstructions.cs | 2 +- .../engine/interpreter/InterpretedFrame.cs | 2 +- .../remoting/client/ClientMethodExecutor.cs | 4 +- .../engine/remoting/client/PSProxyJob.cs | 7 +-- .../engine/remoting/client/remotepipeline.cs | 3 +- .../remoting/commands/InvokeCommandCommand.cs | 11 ++-- .../remoting/common/RunspaceConnectionInfo.cs | 5 -- .../security/Authenticode.cs | 4 +- 25 files changed, 45 insertions(+), 139 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs index 566ec8929f7..67c1ba31efd 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs @@ -288,8 +288,7 @@ protected override void ProcessRecord() { CmdletProviderContext currentContext = CmdletProviderContext; - if (_paths == null || - (_paths != null && _paths.Length == 0)) + if (_paths == null || _paths.Length == 0) { _paths = new string[] { String.Empty }; } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index e16d512b1f1..fb2f92ffff3 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -2362,8 +2362,7 @@ protected override bool ProviderSupportsShouldProcess /// protected override void ProcessRecord() { - if (Path == null || - (Path != null && Path.Length == 0)) + if (Path == null || Path.Length == 0) { Path = new string[] { String.Empty }; } @@ -4533,9 +4532,7 @@ public string[] PSProvider /// protected override void ProcessRecord() { - if (PSProvider == null || - (PSProvider != null && - PSProvider.Length == 0)) + if (PSProvider == null || PSProvider.Length == 0) { // Get all the providers diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs index e8bde3599c2..50554e6b0ae 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs @@ -28,8 +28,7 @@ public class SetContentCommand : WriteContentCommandBase /// internal override void BeforeOpenStreams(string[] paths) { - if (paths == null || - (paths != null && paths.Length == 0)) + if (paths == null || paths.Length == 0) { throw PSTraceSource.NewArgumentNullException("paths"); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index ff713604d3a..5398b1d0091 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -741,8 +741,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert((inputRecords[0].KeyEvent.KeyDown && inputRecords[0].KeyEvent.RepeatCount != 0) || - !inputRecords[0].KeyEvent.KeyDown, + Dbg.Assert(inputRecords[0].KeyEvent.RepeatCount != 0 || !inputRecords[0].KeyEvent.KeyDown, string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[0].KeyEvent.RepeatCount == 0) { @@ -867,8 +866,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[i].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert((inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount != 0) || - !inputRecords[i].KeyEvent.KeyDown, + Dbg.Assert(inputRecords[i].KeyEvent.RepeatCount != 0 || !inputRecords[i].KeyEvent.KeyDown, string.Format(CultureInfo.InvariantCulture, "PeekConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount == 0) diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs index 0adbeab0686..33925edc31d 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs @@ -305,16 +305,9 @@ public void Seek(SeekOrigin origin, long offset) } else { - //if inside the current buffer, we still cannot read the events, as the handles. + //if inside the current buffer (_currentIndex + offset >= 0), we still cannot read the events, as the handles. //may have already been closed. - if (_currentIndex + offset >= 0) - { - SeekCommon(offset); - } - else //outside the current buffer - { - SeekCommon(offset); - } + SeekCommon(offset); } return; } diff --git a/src/Microsoft.PowerShell.PSReadLine/Words.cs b/src/Microsoft.PowerShell.PSReadLine/Words.cs index 5aa0eca46a9..8f2304274ea 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Words.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Words.cs @@ -109,23 +109,11 @@ private int FindForwardWordPoint(string wordDelimiters) if (!InWord(i, wordDelimiters)) { // Scan to end of current non-word region - while (i < _buffer.Length) - { - if (InWord(i, wordDelimiters)) - { - break; - } - i += 1; - } - } - while (i < _buffer.Length) - { - if (!InWord(i, wordDelimiters)) - { - break; - } - i += 1; + for (; i < _buffer.Length && !InWord(i, wordDelimiters); i++) ; } + + for (; i < _buffer.Length && InWord(i, wordDelimiters); i++) ; + return i; } @@ -143,24 +131,10 @@ private int FindNextWordPoint(string wordDelimiters) if (InWord(i, wordDelimiters)) { // Scan to end of current word region - while (i < _singleton._buffer.Length) - { - if (!InWord(i, wordDelimiters)) - { - break; - } - i += 1; - } + for (; i < _singleton._buffer.Length && InWord(i, wordDelimiters); i++) ; } - while (i < _singleton._buffer.Length) - { - if (InWord(i, wordDelimiters)) - { - break; - } - i += 1; - } + for (; i < _singleton._buffer.Length && !InWord(i, wordDelimiters); i++) ; return i; } @@ -178,23 +152,16 @@ private int FindBackwardWordPoint(string wordDelimiters) if (!InWord(i, wordDelimiters)) { // Scan backwards until we are at the end of the previous word. - while (i > 0) - { - if (InWord(i, wordDelimiters)) - { - break; - } - i -= 1; - } + for (; i > 0 && !InWord(i, wordDelimiters); i--) ; } while (i > 0) { if (!InWord(i, wordDelimiters)) { - i += 1; + i++; break; } - i -= 1; + i--; } return i; } diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index a300e55085b..b6faf4aacdf 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -2581,7 +2581,7 @@ private void PutResourceValue(object sessionobj, string ResourceURI, Hashtable v nsmgr.AddNamespace("cfg", uri_schema); string xpath = SetXPathString(ResourceURI); XmlNodeList nodelist = inputxml.SelectNodes(xpath, nsmgr); - if (nodelist.Count == 1 && nodelist != null) + if (nodelist != null && nodelist.Count == 1) { XmlNode node = (XmlNode)nodelist.Item(0); if (node.HasChildNodes) diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index d33423ddf00..33ae31b6a49 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -496,19 +496,13 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, internal string GetXmlNs(string resUri) { - string tmpNs = null; + string tmpNs = StripParams(resUri); - if (resUri.ToLowerInvariant().Contains(URI_IPMI) || (resUri.ToLowerInvariant().Contains(URI_WMI))) - tmpNs = StripParams(resUri); - else - { - //tmpNs = StripParams(resUri) + ".xsd"; - //This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end. - tmpNs = StripParams(resUri); - } + //if (!(resUri.ToLowerInvariant().Contains(URI_IPMI) || resUri.ToLowerInvariant().Contains(URI_WMI))) + // tmpNs += ".xsd"; + //This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end. return (@"xmlns:p=""" + tmpNs + @""""); - } internal XmlNode GetXmlNode(string xmlString, string xpathpattern, string xmlnamespace) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index ead3ac08bb8..a115e568ac2 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -1182,10 +1182,7 @@ private string FindLastWord(out int replacementIndexOut, out char closingQuote) for (_sentenceIndex = 0; _sentenceIndex < _sentence.Length; ++_sentenceIndex) { - Diagnostics.Assert( - (inSingleQuote && !inDoubleQuote) - || (inDoubleQuote && !inSingleQuote) - || (!inSingleQuote && !inDoubleQuote), + Diagnostics.Assert(!(inSingleQuote && inDoubleQuote), "Can't be in both single and double quotes"); char c = _sentence[_sentenceIndex]; diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index 8de45b9c69e..2f848467763 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -862,10 +862,7 @@ private static int CompareOverloadCandidates(OverloadCandidate candidate1, Overl return 0; } } - } - if (betterCount == 0) - { // Apply tie breaking rules, related to expanded parameters if (candidate1.expandedParameters != null && candidate2.expandedParameters != null) { @@ -880,10 +877,8 @@ private static int CompareOverloadCandidates(OverloadCandidate candidate1, Overl { return 1; } - } - if (betterCount == 0) - { + // Apply tie breaking rules, related to specificity of parameters betterCount = CompareTypeSpecificity(candidate1, candidate2); } diff --git a/src/System.Management.Automation/engine/DataStoreAdapter.cs b/src/System.Management.Automation/engine/DataStoreAdapter.cs index 6ababeb0c57..726d5af89b9 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapter.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapter.cs @@ -856,16 +856,9 @@ public bool Equals(PSDriveInfo drive) if ((drive1Object == null)) { - if (drive2Object == null) - { - // Since both drives are null, they are equal - return false; - } - else - { - // Since drive1 is null it is less than drive2 which is not null - return false; - } + // Since both drives are null, they are equal + // Since drive1 is null it is less than drive2 which is not null + return false; } else { diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs index a8286ec146d..ee8ec1022e7 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs @@ -405,11 +405,7 @@ internal ProviderInfo( throw PSTraceSource.NewArgumentException("name"); } - - if (String.IsNullOrEmpty(name)) - { - throw PSTraceSource.NewArgumentException("name"); - } + // FIXME: Other checks? _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index cc4ab30645e..3e5e7b9830f 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -3691,7 +3691,7 @@ internal object Convert(object valueToConvert, ExecutionContext ecFromTLS = LocalPipeline.GetExecutionContextFromTLS(); object result = null; - if ((ecFromTLS == null) || (ecFromTLS != null && ecFromTLS.LanguageMode == PSLanguageMode.FullLanguage)) + if (ecFromTLS == null || ecFromTLS.LanguageMode == PSLanguageMode.FullLanguage) { result = _constructor(); var psobject = valueToConvert as PSObject; diff --git a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs index 19809589557..4f01415879e 100644 --- a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs +++ b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs @@ -634,14 +634,14 @@ public void QueueSerialization() // Wait a while before assuming we've finished the updates, // writing the cache out in a timely matter isn't too important // now anyway. - await Task.Delay(10000); + await Task.Delay(10000).ConfigureAwait(false); int counter1, counter2; do { // Check the counter a couple times with a delay, // if it's stable, then proceed with writing. counter1 = _saveCacheToDiskQueued; - await Task.Delay(3000); + await Task.Delay(3000).ConfigureAwait(false); counter2 = _saveCacheToDiskQueued; } while (counter1 != counter2); Serialize(s_cacheStoreLocation); diff --git a/src/System.Management.Automation/engine/SessionStatePublic.cs b/src/System.Management.Automation/engine/SessionStatePublic.cs index e1bf6cbd26c..0fa35a25075 100644 --- a/src/System.Management.Automation/engine/SessionStatePublic.cs +++ b/src/System.Management.Automation/engine/SessionStatePublic.cs @@ -208,9 +208,7 @@ public static void ThrowIfNotVisible(CommandOrigin origin, object valueToCheck) CommandInfo cinfo = valueToCheck as CommandInfo; if (cinfo != null) { - string commandName = null; - if (cinfo != null) - commandName = cinfo.Name; + string commandName = cinfo.Name; if (commandName != null) { // If we have a name, use it in the error message diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 5db5e5171df..76376f36a3b 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -4432,11 +4432,7 @@ private void CoreInvoke(PSDataCollection input, PSDataC finally { RunningExtraCommands = false; - - if (_isBatching) - { - EndAsyncBatchExecution(); - } + EndAsyncBatchExecution(); } } else diff --git a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs index 88795b73cd8..bcaca8bda38 100644 --- a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs +++ b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs @@ -213,7 +213,7 @@ private static Type TryGetParameterOrReturnType(MethodInfo target, ParameterInfo private static bool IndexIsNotReturnType(int index, MethodInfo target, ParameterInfo[] pi) { - return pi.Length != index || (pi.Length == index && !target.IsStatic); + return pi.Length != index || !target.IsStatic; } /// diff --git a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs index 6fdc756e7ab..9bf1630c92b 100644 --- a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs +++ b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs @@ -429,7 +429,7 @@ public override int Run(InterpretedFrame frame) // In the second path, the continuation mechanism is not involved and frame.InstructionIndex is not updated #if DEBUG bool isFromJump = frame.IsJumpHappened(); - Debug.Assert(!isFromJump || (isFromJump && _tryHandler.FinallyStartIndex == frame.InstructionIndex), "we should already jump to the first instruction of the finally"); + Debug.Assert(!isFromJump || _tryHandler.FinallyStartIndex == frame.InstructionIndex, "we should already jump to the first instruction of the finally"); #endif // run the finally block // we cannot jump out of the finally block, and we cannot have an immediate rethrow in it diff --git a/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs b/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs index 1cd7894b911..7f89a41edcd 100644 --- a/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs +++ b/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs @@ -313,7 +313,7 @@ public int Goto(int labelIndex, object value, bool gotoExceptionHandler) { // TODO: we know this at compile time (except for compiled loop): RuntimeLabel target = Interpreter._labels[labelIndex]; - Debug.Assert(!gotoExceptionHandler || (gotoExceptionHandler && _continuationIndex == target.ContinuationStackDepth), + Debug.Assert(!gotoExceptionHandler || _continuationIndex == target.ContinuationStackDepth, "When it's time to jump to the exception handler, all previous finally blocks should already be processed"); if (_continuationIndex == target.ContinuationStackDepth) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs index a1ba8526465..13d46759f06 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs @@ -118,9 +118,7 @@ internal static void Dispatch( // Cmdlet case: queue up the executor in the pipeline stream. if (isMethodExecutorStreamEnabled) { - Dbg.Assert(!isMethodExecutorStreamEnabled || - (isMethodExecutorStreamEnabled && methodExecutorStream != null), - "method executor stream can't be null when enabled"); + Dbg.Assert(methodExecutorStream != null, "method executor stream can't be null when enabled"); methodExecutorStream.Write(methodExecutor); } diff --git a/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs b/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs index 3f9bbe36327..59f40b58c9c 100644 --- a/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs +++ b/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs @@ -769,8 +769,7 @@ private static ICollection Create(Runspace runspace, RunspacePool ru using (PowerShell ps = PowerShell.Create()) { - Dbg.Assert(runspacePool == null && runspace != null || - runspace == null && runspacePool != null, "Either a runspace or a runspacepool should be used, not both."); + Dbg.Assert(runspacePool == null ^ runspace == null, "Either a runspace or a runspacepool should be used, not both."); if (runspacePool == null) { @@ -1493,9 +1492,7 @@ private void CleanupReceivePowerShell(IAsyncResult asyncResult) /// happen private void AssignRunspaceOrRunspacePool(PowerShell powershell) { - Dbg.Assert(_runspacePool == null && _runspace != null || - _runspace == null && _runspacePool != null, - "Either a runspace or a runspacepool should be assigned to the proxy job"); + Dbg.Assert(_runspacePool == null ^ _runspace == null, "Either a runspace or a runspacepool should be assigned to the proxy job"); if (_runspacePool == null) { diff --git a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs index 73629a3f62a..fdd34196432 100644 --- a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs +++ b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs @@ -912,8 +912,7 @@ private void InitPowerShellForConnect(bool syncCall) // Check to see if this pipeline already exists in the runspace. RemotePipeline currentPipeline = (RemotePipeline)((RemoteRunspace)_runspace).GetCurrentlyRunningPipeline(); - if (currentPipeline == null || - currentPipeline != null && !ReferenceEquals(currentPipeline, this)) + if (currentPipeline == null || !ReferenceEquals(currentPipeline, this)) { ((RemoteRunspace)_runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); } diff --git a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs index 813e3161716..842b0206f07 100644 --- a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs @@ -1173,10 +1173,7 @@ protected override void EndProcessing() WriteJobResults(false); // finally dispose the job. - if (!_asjob) - { - _job.Dispose(); - } + _job.Dispose(); // We no longer need to call ClearInvokeCommandOnRunspaces() here because // this command might finish before the foreach block finishes. previously, @@ -1223,10 +1220,8 @@ protected override void EndProcessing() WriteJobResults(false); // finally dispose the job. - if (!_asjob) - { - _job.Dispose(); - } + _job.Dispose(); + } // if (needToCollect... }// else - job == null } diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index 2616ed72cf3..4860f782d13 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -1212,11 +1212,6 @@ internal void ConstructUri(String scheme, String computerName, Nullable p PortSetting = -1; UseDefaultWSManPort = true; } - else if (port.Value == DefaultPortHttp || port.Value == DefaultPortHttps) - { - PortSetting = port.Value; - UseDefaultWSManPort = false; - } else { PortSetting = port.Value; diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index d79aad4b0f9..79b365eedc7 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -619,9 +619,9 @@ private static Signature GetSignatureFromWintrustData( } } - Diagnostics.Assert(((error == 0) && (signature != null)) || (error != 0), "GetSignatureFromWintrustData: general crypto failure"); + Diagnostics.Assert(error != 0 || signature != null, "GetSignatureFromWintrustData: general crypto failure"); - if ((signature == null) && (error != 0)) + if (signature == null && error != 0) { signature = new Signature(filePath, error); } From 4effc484fd1fe837d65932d02225d85f9c8be6f0 Mon Sep 17 00:00:00 2001 From: "v.glagolev" Date: Tue, 17 Oct 2017 15:07:49 +0300 Subject: [PATCH 2/2] Changes to PR from the Team --- .../host/msh/ConsoleHostRawUserInterface.cs | 4 +- .../Eventing/Reader/EventLogReader.cs | 2 - src/Microsoft.PowerShell.PSReadLine/Words.cs | 51 +++++++++++++++---- src/Microsoft.WSMan.Management/WsManHelper.cs | 9 +--- .../engine/DataStoreAdapter.cs | 13 +---- .../engine/DataStoreAdapterProvider.cs | 2 - .../engine/remoting/client/remotepipeline.cs | 2 +- .../security/Authenticode.cs | 2 +- 8 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 5398b1d0091..0a73bdcac89 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -741,7 +741,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert(inputRecords[0].KeyEvent.RepeatCount != 0 || !inputRecords[0].KeyEvent.KeyDown, + Dbg.Assert(!inputRecords[0].KeyEvent.KeyDown || inputRecords[0].KeyEvent.RepeatCount != 0, string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[0].KeyEvent.RepeatCount == 0) { @@ -866,7 +866,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[i].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert(inputRecords[i].KeyEvent.RepeatCount != 0 || !inputRecords[i].KeyEvent.KeyDown, + Dbg.Assert(!inputRecords[i].KeyEvent.KeyDown || inputRecords[i].KeyEvent.RepeatCount != 0, string.Format(CultureInfo.InvariantCulture, "PeekConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount == 0) diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs index 33925edc31d..668e02a1a82 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs @@ -305,8 +305,6 @@ public void Seek(SeekOrigin origin, long offset) } else { - //if inside the current buffer (_currentIndex + offset >= 0), we still cannot read the events, as the handles. - //may have already been closed. SeekCommon(offset); } return; diff --git a/src/Microsoft.PowerShell.PSReadLine/Words.cs b/src/Microsoft.PowerShell.PSReadLine/Words.cs index 8f2304274ea..5aa0eca46a9 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Words.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Words.cs @@ -109,11 +109,23 @@ private int FindForwardWordPoint(string wordDelimiters) if (!InWord(i, wordDelimiters)) { // Scan to end of current non-word region - for (; i < _buffer.Length && !InWord(i, wordDelimiters); i++) ; + while (i < _buffer.Length) + { + if (InWord(i, wordDelimiters)) + { + break; + } + i += 1; + } + } + while (i < _buffer.Length) + { + if (!InWord(i, wordDelimiters)) + { + break; + } + i += 1; } - - for (; i < _buffer.Length && InWord(i, wordDelimiters); i++) ; - return i; } @@ -131,10 +143,24 @@ private int FindNextWordPoint(string wordDelimiters) if (InWord(i, wordDelimiters)) { // Scan to end of current word region - for (; i < _singleton._buffer.Length && InWord(i, wordDelimiters); i++) ; + while (i < _singleton._buffer.Length) + { + if (!InWord(i, wordDelimiters)) + { + break; + } + i += 1; + } } - for (; i < _singleton._buffer.Length && !InWord(i, wordDelimiters); i++) ; + while (i < _singleton._buffer.Length) + { + if (InWord(i, wordDelimiters)) + { + break; + } + i += 1; + } return i; } @@ -152,16 +178,23 @@ private int FindBackwardWordPoint(string wordDelimiters) if (!InWord(i, wordDelimiters)) { // Scan backwards until we are at the end of the previous word. - for (; i > 0 && !InWord(i, wordDelimiters); i--) ; + while (i > 0) + { + if (InWord(i, wordDelimiters)) + { + break; + } + i -= 1; + } } while (i > 0) { if (!InWord(i, wordDelimiters)) { - i++; + i += 1; break; } - i--; + i -= 1; } return i; } diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index 33ae31b6a49..7608a1a0c79 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -495,14 +495,7 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, internal string GetXmlNs(string resUri) { - - string tmpNs = StripParams(resUri); - - //if (!(resUri.ToLowerInvariant().Contains(URI_IPMI) || resUri.ToLowerInvariant().Contains(URI_WMI))) - // tmpNs += ".xsd"; - //This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end. - - return (@"xmlns:p=""" + tmpNs + @""""); + return (@"xmlns:p=""" + StripParams(resUri) + @""""); } internal XmlNode GetXmlNode(string xmlString, string xpathpattern, string xmlnamespace) diff --git a/src/System.Management.Automation/engine/DataStoreAdapter.cs b/src/System.Management.Automation/engine/DataStoreAdapter.cs index 726d5af89b9..4685a29e3a1 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapter.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapter.cs @@ -804,18 +804,9 @@ public bool Equals(PSDriveInfo drive) Object drive1Object = drive1; Object drive2Object = drive2; - if ((drive1Object == null)) + if (drive1Object == null) { - if (drive2Object == null) - { - // Since both drives are null, they are equal - return false; - } - else - { - // Since drive1 is null it is less than drive2 which is not null - return true; - } + return (drive2Object != null); } else { diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs index ee8ec1022e7..33cd2e3df78 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs @@ -405,8 +405,6 @@ internal ProviderInfo( throw PSTraceSource.NewArgumentException("name"); } - // FIXME: Other checks? - _sessionState = sessionState; Name = name; diff --git a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs index fdd34196432..37b7f41647b 100644 --- a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs +++ b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs @@ -912,7 +912,7 @@ private void InitPowerShellForConnect(bool syncCall) // Check to see if this pipeline already exists in the runspace. RemotePipeline currentPipeline = (RemotePipeline)((RemoteRunspace)_runspace).GetCurrentlyRunningPipeline(); - if (currentPipeline == null || !ReferenceEquals(currentPipeline, this)) + if (!ReferenceEquals(currentPipeline, this)) { ((RemoteRunspace)_runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); } diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index 79b365eedc7..d5d671b275d 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -621,7 +621,7 @@ private static Signature GetSignatureFromWintrustData( Diagnostics.Assert(error != 0 || signature != null, "GetSignatureFromWintrustData: general crypto failure"); - if (signature == null && error != 0) + if ((signature == null) && (error != 0)) { signature = new Signature(filePath, error); }