FP S2583: Conditionally executed code should be reachable - Pre-increment in if statement
eduherminio opened this issue · 2 comments
eduherminio commented
Description
FP S2583: the code definitely gets executed.
Repro steps
int counter = 0;
for (int i = 0; i < 1000; ++i)
{
if (++counter % 100 == 0) // S2583
{
Thread.Sleep(50);
}
}
Expected behavior
No warning
Actual behavior
Known workarounds
Please provide a description of any known workarounds.
int counter = 0;
for (int i = 0; i < 1000; ++i)
{
++counter;
if (counter % 100 == 0) // No S2583
{
Thread.Sleep(50);
}
}
Related information
- C#/VB.NET Plugins version: 7.3.0.77872
- Visual Studio version: 17.10.2
- MSBuild / dotnet version: 8.0.300
- SonarScanner for .NET version (if used):
- Operating System: Windows
zsolt-kolbay-sonarsource commented
@eduherminio I've been unable to replicate the FP with the following code:
namespace Repro_9443
{
public class SomeClass
{
public void PreIncrementInLoop()
{
int counter = 0;
for (int i = 0; i < 1000; ++i)
{
if (++counter % 100 == 0) // S2583
{
System.Threading.Thread.Sleep(50);
}
}
}
}
}
The analyzer version you're using (7.3.0.77872) is very old. Could you try it with the latest version (9.27 as of date) and see if the FP is still there?
eduherminio commented
Oh, VS wasn't showing a newer version, so I assumed I was using the latest one.
It doesn't show up in the version 8.0.0.92083
of the extension, so problem solved, sorry for the FFP!