Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S4158: Add fixed FP repro for #6179 #7446

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,35 @@ public interface IDecoder
{
bool Convert(out int i3, out int i4);
}

// https://github.com/SonarSource/sonar-dotnet/issues/6179
public class Repro_6179
{
public void FilledInLoop_FromAnotherCollection()
{
var data = new[] { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 };
var list = new List<List<int>>();
List<int> currentBin = null;
for (var i = 0; i < data.Length; i++)
{
if (data[i] == 0)
{
if (currentBin != null)
{
list.Add(currentBin);
currentBin = null;
}

continue;
}

currentBin ??= new List<int>();
currentBin.Add(i);
}

for (var i = 0; i < list.Count; i++)
{
list.ForEach(x => { }); // Noncompliant
}
}
}