Description
S2583 is raised in a while(true) loop with nested conditions.
Repro steps
Compile and run the following code:
namespace SonarRepo
{
using System;
using System.Net;
public static class Program
{
private static void Main()
{
Run();
}
public static void Run()
{
HttpStatusCode? statusCode = null;
var contentLength = 0;
while (true)
{
var response = "5";
if (response is null)
{
// server shut down socket
break;
}
if (statusCode is null)
{
statusCode = HttpStatusCode.OK;
continue;
}
// continue on parsing message headers coming from the server
if (response == "5" && contentLength == 0)
{
contentLength = 7;
continue;
}
if (response.Length > 0)
{
if (contentLength > 0)
{
Console.WriteLine("And you thought we were unreachable??");
}
break;
}
}
}
}
}
Expected behavior
S2583 is not reported, and the application writes the following to standard output:
And you thought we were unreachable??
Actual behavior
S2583 is reported, and the application writes the following to standard output:
And you thought we were unreachable??
Known workarounds
None.
Related information
- SonarAnalyzer.CSharp version: 9.12.0.78982
- Visual Studio version: 17.8.0 Preview 2.0
Description
S2583 is raised in a
while(true)loop with nested conditions.Repro steps
Compile and run the following code:
Expected behavior
S2583 is not reported, and the application writes the following to standard output:
Actual behavior
S2583 is reported, and the application writes the following to standard output:
Known workarounds
None.
Related information