Fix code errors found by PVS-Studio (#2695)

* Fix errors found by PSV-studio analyzer

http://www.viva64.com/en/b/0447/

* Remove old redundent comment

errorAsts is passed by ref
This commit is contained in:
Sergei Vorobev
2016-11-17 11:20:04 -08:00
committed by Jason Shirk
parent ce26bca8db
commit 3363b248a0
13 changed files with 19 additions and 24 deletions
@@ -349,7 +349,7 @@ namespace System.Management.Automation
internal bool SafeForExport()
{
return DisplayEntry.SafeForExport() &&
ItemSelectionCondition == null || ItemSelectionCondition.SafeForExport();
(ItemSelectionCondition == null || ItemSelectionCondition.SafeForExport());
}
internal bool CompatibleWithOldPowerShell()
@@ -244,7 +244,7 @@ namespace System.Management.Automation
internal bool SafeForExport()
{
return DisplayEntry.SafeForExport() && EntrySelectedBy == null || EntrySelectedBy.SafeForExport();
return DisplayEntry.SafeForExport() && (EntrySelectedBy == null || EntrySelectedBy.SafeForExport());
}
internal bool CompatibleWithOldPowerShell()
@@ -433,8 +433,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
TraversalInfo level = new TraversalInfo(0, maxDepth);
List<MshParameter> mshParameterList = null;
if (inputParameters != null)
mshParameterList = inputParameters.mshParameterList;
mshParameterList = inputParameters.mshParameterList;
// create a top level entry as root of the tree
ComplexViewEntry cve = new ComplexViewEntry();
@@ -189,12 +189,9 @@ namespace System.Management.Automation
_parameters = new Dictionary<string, ParameterMetadata>(other.Parameters.Count, StringComparer.OrdinalIgnoreCase);
// deep copy
if (other.Parameters != null)
foreach (KeyValuePair<string, ParameterMetadata> entry in other.Parameters)
{
foreach (KeyValuePair<string, ParameterMetadata> entry in other.Parameters)
{
_parameters.Add(entry.Key, new ParameterMetadata(entry.Value));
}
_parameters.Add(entry.Key, new ParameterMetadata(entry.Value));
}
// deep copy of the collection, collection items (Attributes) copied by reference
@@ -1129,7 +1129,7 @@ namespace System.Management.Automation
{
PopulateProperties(exception, targetObject, fullyQualifiedErrorId, errorCategory, errorCategory_Activity,
errorCategory_Reason, errorCategory_TargetName, errorCategory_TargetType,
errorDetails_Message, errorDetails_Message, errorDetails_RecommendedAction, null);
errorCategory_Message, errorDetails_Message, errorDetails_RecommendedAction, null);
}
private void PopulateProperties(Exception exception,
@@ -1660,7 +1660,7 @@ namespace Microsoft.PowerShell.Commands
/// </remarks>
protected override void ProcessRecord()
{
if (BaseMaximumVersion != null && BaseMaximumVersion != null && BaseMaximumVersion < BaseMinimumVersion)
if (BaseMaximumVersion != null && BaseMinimumVersion != null && BaseMaximumVersion < BaseMinimumVersion)
{
string message = StringUtil.Format(Modules.MinimumVersionAndMaximumVersionInvalidRange, BaseMinimumVersion, BaseMaximumVersion);
throw new PSArgumentOutOfRangeException(message);
@@ -1001,7 +1001,7 @@ namespace System.Management.Automation
{
ProviderNotFoundException e =
new ProviderNotFoundException(
providerName.ToString(),
"null",
SessionStateCategory.CmdletProvider,
"ProviderNotFound",
SessionStateStrings.ProviderNotFound);
@@ -574,14 +574,14 @@ namespace System.Management.Automation.Runspaces.Internal
int unUsedCapacity = (maxPoolSz - totalRunspaces) < 0 ? 0 : (maxPoolSz - totalRunspaces);
return (pool.Count + unUsedCapacity);
}
else if (stateInfo.State != RunspacePoolState.BeforeOpen && stateInfo.State != RunspacePoolState.Opening)
{
throw new InvalidOperationException(HostInterfaceExceptionsStrings.RunspacePoolNotOpened);
}
else if (stateInfo.State == RunspacePoolState.Disconnected)
{
throw new InvalidOperationException(RunspacePoolStrings.CannotWhileDisconnected);
}
else if (stateInfo.State != RunspacePoolState.BeforeOpen && stateInfo.State != RunspacePoolState.Opening)
{
throw new InvalidOperationException(HostInterfaceExceptionsStrings.RunspacePoolNotOpened);
}
else
{
return maxPoolSz;
@@ -4970,9 +4970,8 @@ namespace System.Management.Automation.Language
}
else
{
errorAsts.Concat(exceptionTypes);
errorAsts.AddRange(exceptionTypes);
}
// REVIEW: seems like some code is missing here, errorAsts isn't used
}
return null;
}
@@ -1873,7 +1873,7 @@ namespace System.Management.Automation
foreach (Job j in ChildJobs)
{
PSRemotingChildJob child = j as PSRemotingChildJob;
if (j == null) continue;
if (child == null) continue;
if (String.Equals(child.Runspace.ConnectionInfo.ComputerName, computerName,
StringComparison.OrdinalIgnoreCase))
{
@@ -1897,7 +1897,7 @@ namespace System.Management.Automation
foreach (Job j in ChildJobs)
{
PSRemotingChildJob child = j as PSRemotingChildJob;
if (j == null) continue;
if (child == null) continue;
if (child.Runspace.InstanceId.Equals(runspace.InstanceId))
{
returnJobList.Add(child);
@@ -1920,7 +1920,7 @@ namespace System.Management.Automation
foreach (Job j in ChildJobs)
{
PSRemotingChildJob child = j as PSRemotingChildJob;
if (j == null) continue;
if (child == null) continue;
if (child.Helper.Equals(helper))
{
returnJobList.Add(child);
@@ -630,7 +630,7 @@ namespace System.Management.Automation.Remoting
int clientRequestedMinRunspaces = -1;
int clientRequestedMaxRunspaces = -1;
bool clientRequestedRunspaceCount = false;
if (connectRunspacePoolObject.Data.Properties[RemoteDataNameStrings.MinRunspaces] != null && connectRunspacePoolObject.Data.Properties[RemoteDataNameStrings.MinRunspaces] != null)
if (connectRunspacePoolObject.Data.Properties[RemoteDataNameStrings.MinRunspaces] != null && connectRunspacePoolObject.Data.Properties[RemoteDataNameStrings.MaxRunspaces] != null)
{
try
{
@@ -4125,7 +4125,7 @@ namespace Microsoft.PowerShell.Commands
{
// Check if the remote source file has any alternate data streams
ArrayList remoteFileStreams = GetRemoteSourceAlternateStreams(ps, sourceFileFullName);
if ((remoteFileStreams.Count > 0) && (remoteFileStreams != null))
if ((remoteFileStreams != null) && (remoteFileStreams.Count > 0))
{
foreach (string streamName in remoteFileStreams)
{
@@ -1085,7 +1085,7 @@ namespace System.Management.Automation.Tracing
{
return DebugChannel.TraceDebug(PowerShellTraceEvent.Job,
PowerShellTraceOperationCode.Method, PowerShellTraceTask.None,
job.Id.ToString(CultureInfo.InvariantCulture), job.InstanceId.ToString(), "NULL job");
"", "", "NULL job");
}
}