Avoid usage of do statement to create an infinite loop (#13137)

* Autofix RCS1063
This commit is contained in:
xtqqczze
2020-07-20 09:23:14 +05:00
committed by GitHub
parent f82f74d898
commit 2c18386d79
20 changed files with 49 additions and 56 deletions
@@ -857,7 +857,7 @@ namespace Microsoft.PowerShell.Commands
string errorId,
string errorMessage)
{
do
while (true)
{
try
{
@@ -891,7 +891,7 @@ namespace Microsoft.PowerShell.Commands
// will throw PipelineStoppedException if user hit CTRL-C
WriteWarning(message);
}
} while (true);
}
}
/// <summary>
@@ -418,7 +418,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
private void WaitForWindowClosedOrHelpNeeded()
{
do
while (true)
{
int which = WaitHandle.WaitAny(new WaitHandle[] { _showCommandProxy.WindowClosed, _showCommandProxy.HelpNeeded, _showCommandProxy.ImportModuleNeeded });
@@ -452,7 +452,6 @@ namespace Microsoft.PowerShell.Commands
_showCommandProxy.ImportModuleDone(_importedModules, _commands);
continue;
}
while (true);
}
/// <summary>
@@ -335,7 +335,7 @@ namespace Microsoft.PowerShell
Coordinates originalCursorPos = _rawui.CursorPosition;
do
while (true)
{
//
// read one char at a time so that we don't
@@ -426,7 +426,6 @@ namespace Microsoft.PowerShell
}
}
}
while (true);
}
#if UNIX
catch (InvalidOperationException)
@@ -1149,7 +1148,7 @@ namespace Microsoft.PowerShell
w.Flags = WordFlags.IsWhitespace;
}
do
while (true)
{
w.Text = text.Substring(startIndex, i - startIndex);
w.CellCount = RawUI.LengthInBufferCells(w.Text);
@@ -1165,7 +1164,7 @@ namespace Microsoft.PowerShell
--i;
}
} while (true);
}
Dbg.Assert(RawUI.LengthInBufferCells(w.Text) <= maxWidthInBufferCells, "word should not exceed max");
result.Add(w);
@@ -1621,7 +1620,7 @@ namespace Microsoft.PowerShell
}
#endif
do
while (true)
{
#if UNIX
keyInfo = Console.ReadKey(true);
@@ -1848,7 +1847,6 @@ namespace Microsoft.PowerShell
Console.CursorLeft = cursorCurrent + 1;
#endif
}
while (true);
Dbg.Assert(
(s == null && result == ReadLineResult.endedOnBreak)
@@ -1949,7 +1947,7 @@ namespace Microsoft.PowerShell
string completionInput = null;
#endif
do
while (true)
{
if (TryInvokeUserDefinedReadLine(out input))
{
@@ -2081,7 +2079,6 @@ namespace Microsoft.PowerShell
}
#endif
}
while (true);
// Since we did not transcribe any call to ReadLine, transcribe the results here.
@@ -91,7 +91,7 @@ namespace Microsoft.PowerShell
defaultChoiceKeys.Add(defaultChoice, true);
}
do
while (true)
{
WriteChoicePrompt(hotkeysAndPlainLabels, defaultChoiceKeys, false);
@@ -140,7 +140,6 @@ namespace Microsoft.PowerShell
// their input matched none of the choices, so prompt again
}
while (true);
return result;
}
@@ -231,7 +230,7 @@ namespace Microsoft.PowerShell
// used to display ChoiceMessage like Choice[0],Choice[1] etc
int choicesSelected = 0;
do
while (true)
{
// write the current prompt
string choiceMsg = StringUtil.Format(ConsoleHostUserInterfaceStrings.ChoiceMessage, choicesSelected);
@@ -286,7 +285,6 @@ namespace Microsoft.PowerShell
}
// prompt for multiple choices
}
while (true);
return result;
}
@@ -337,7 +337,7 @@ namespace Microsoft.PowerShell
ProgressNode result = null;
ArrayList treeToSearch = _topLevelNodes;
do
while (true)
{
result = FindOldestLeafmostNodeHelper(treeToSearch, out listWhereFound, out indexWhereFound);
if (result == null || result.Children == null || result.Children.Count == 0)
@@ -348,7 +348,7 @@ namespace Microsoft.PowerShell
// search the subtree for the oldest child
treeToSearch = result.Children;
} while (true);
}
return result;
}
@@ -838,7 +838,7 @@ namespace Microsoft.PowerShell
int age = 0;
do
while (true)
{
ProgressNode node = FindOldestNodeOfGivenStyle(_topLevelNodes, age, priorStyle);
if (node == null)
@@ -854,7 +854,7 @@ namespace Microsoft.PowerShell
{
return true;
}
} while (true);
}
// If we get all the way to here, then we've compressed all the nodes and we still don't fit.
@@ -278,9 +278,9 @@ namespace System.Management.Automation
GetNewDirectoryResults(_patternEnumerator.Current, _lookupPathsEnumerator.Current);
}
do // while lookupPathsEnumerator is valid
while (true) // while lookupPathsEnumerator is valid
{
do // while patternEnumerator is valid
while (true) // while patternEnumerator is valid
{
// Try moving to the next path in the current results
@@ -309,7 +309,7 @@ namespace System.Management.Automation
}
// Since we have reset the results, loop again to find the next result.
} while (true);
}
if (result)
{
@@ -336,7 +336,7 @@ namespace System.Management.Automation
}
GetNewDirectoryResults(_patternEnumerator.Current, _lookupPathsEnumerator.Current);
} while (true);
}
return result;
}
@@ -950,7 +950,7 @@ namespace Microsoft.PowerShell.Commands
bool resultFound = false;
isDuplicate = false;
do
while (true)
{
try
{
@@ -1057,7 +1057,7 @@ namespace Microsoft.PowerShell.Commands
break;
}
}
} while (true);
}
if (All)
{
@@ -388,7 +388,7 @@ namespace System.Management.Automation
SearchResolutionOptions.None,
CommandTypes.Cmdlet,
context);
do
while (true)
{
try
{
@@ -419,7 +419,7 @@ namespace System.Management.Automation
}
current = ((IEnumerator)searcher).Current as CmdletInfo;
} while (true);
}
return current;
}
@@ -497,7 +497,7 @@ namespace System.Management.Automation
SearchResolutionOptions.CommandNameIsPattern,
CommandTypes.Cmdlet,
_context);
do
while (true)
{
try
{
@@ -530,7 +530,7 @@ namespace System.Management.Automation
current = ((IEnumerator)searcher).Current as CmdletInfo;
if (current != null)
cmdlets.Add(current);
} while (true);
}
return cmdlets;
}
@@ -631,7 +631,7 @@ namespace System.Management.Automation
searcher.CommandOrigin = commandOrigin.Value;
}
do
while (true)
{
try
{
@@ -666,7 +666,7 @@ namespace System.Management.Automation
{
yield return commandInfo;
}
} while (true);
}
}
/// <summary>
@@ -3620,7 +3620,7 @@ namespace System.Management.Automation
inquireCaption = CommandBaseStrings.InquireCaptionDefault;
}
do
while (true)
{
// Transcribe the confirmation message
CBhost.InternalUI.TranscribeResult(inquireCaption);
@@ -3694,7 +3694,7 @@ namespace System.Management.Automation
PSTraceSource.NewInvalidOperationException();
throw ManageException(e);
}
} while (true);
}
}
/// <summary>
@@ -1034,7 +1034,7 @@ namespace System.Management.Automation.Internal.Host
// read choices from the user
Collection<int> result = new Collection<int>();
int choicesSelected = 0;
do
while (true)
{
string choiceMsg = StringUtil.Format(InternalHostUserInterfaceStrings.ChoiceMessage, choicesSelected);
messageToBeDisplayed += choiceMsg;
@@ -1071,7 +1071,7 @@ namespace System.Management.Automation.Internal.Host
}
// reset messageToBeDisplayed
messageToBeDisplayed = string.Empty;
} while (true);
}
return result;
}
@@ -1940,7 +1940,7 @@ namespace System.Management.Automation
{
lock (_collToEnumerate.SyncObject)
{
do
while (true)
{
if (_index < _collToEnumerate.Count)
{
@@ -1979,7 +1979,7 @@ namespace System.Management.Automation
{
return false;
}
} while (true);
}
}
}
@@ -1510,7 +1510,7 @@ namespace System.Management.Automation.Runspaces.Internal
try
{
do
while (true)
{
lock (ultimateRequestQueue)
{
@@ -1591,7 +1591,7 @@ namespace System.Management.Automation.Runspaces.Internal
ultimateRequestQueue.Enqueue(runspaceRequestQueue.Dequeue());
}
}
} while (true);
}
endOuterWhile:;
}
finally
@@ -5444,7 +5444,7 @@ namespace System.Management.Automation.Language
List<TypeConstraintAst> exceptionTypes = null;
Token commaToken = null;
do
while (true)
{
var restorePoint = _tokenizer.GetRestorePoint();
SkipNewlines();
@@ -5493,7 +5493,7 @@ namespace System.Management.Automation.Language
}
SkipToken();
} while (true);
}
StatementBlockAst handler = StatementBlockRule();
if (handler == null)
@@ -2618,7 +2618,7 @@ namespace System.Management.Automation.Language
nameof(ParserStrings.UnexpectedCharactersAfterHereStringHeader),
ParserStrings.UnexpectedCharactersAfterHereStringHeader);
do
while (true)
{
c = GetChar();
if (c == header[1] && (PeekChar() == '@'))
@@ -2632,7 +2632,7 @@ namespace System.Management.Automation.Language
UngetChar();
break;
}
} while (true);
}
return false;
}
@@ -805,7 +805,7 @@ namespace System.Management.Automation.Remoting.Client
try
{
do
while (true)
{
// if the transport manager is closed return.
if (isClosed)
@@ -843,7 +843,7 @@ namespace System.Management.Automation.Remoting.Client
base.OnDataAvailableCallback(rcvdDataInfo.remoteObject);
}
}
} while (true);
}
}
catch (Exception exception)
{
@@ -455,7 +455,7 @@ namespace System.Management.Automation.Remoting
// this do loop will process one deserialized object.
// using a loop allows to process multiple objects within
// the same packet
do
while (true)
{
if (_pendingDataStream.Length <= FragmentedRemoteObject.HeaderLength)
{
@@ -651,7 +651,7 @@ namespace System.Management.Automation.Remoting
break;
}
}
} while (true);
}
}
finally
{
@@ -343,7 +343,7 @@ namespace System.Management.Automation.Remoting.Server
try
{
do
while (true)
{
string data = originalStdIn.ReadLine();
lock (_syncObject)
@@ -381,7 +381,6 @@ namespace System.Management.Automation.Remoting.Server
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessingThreadStart), data);
#endif
}
while (true);
}
catch (Exception e)
{
@@ -1382,7 +1382,7 @@ namespace Microsoft.PowerShell.Commands
}
}
do
while (true)
{
while (_charCount > 0)
{
@@ -1403,7 +1403,7 @@ namespace Microsoft.PowerShell.Commands
line.Remove(line.Length - charsToRemove, charsToRemove);
return line.ToString();
}
} while (true);
}
}
/// <summary>
@@ -1517,7 +1517,7 @@ namespace Microsoft.PowerShell.Commands
bool result = false;
do
while (true)
{
// See if the paths are equal
@@ -1550,7 +1550,7 @@ namespace Microsoft.PowerShell.Commands
}
destinationPath = newDestinationPath;
} while (true);
}
if (result)
{
@@ -42,7 +42,7 @@ namespace System.Management.Automation.Internal
string result;
int i = Math.Min(toTruncate.Length, maxWidthInBufferCells);
do
while (true)
{
result = toTruncate.Substring(0, i);
int cellCount = rawUI.LengthInBufferCells(result);
@@ -59,7 +59,7 @@ namespace System.Management.Automation.Internal
// be characters taking more 2 buffer cells
--i;
}
} while (true);
}
return result;
}