Skip to content

Commit

Permalink
S2589: Add FP Repro for #8570 (#8759)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-paidis-sonarsource committed Feb 14, 2024
1 parent ecf5aea commit 6069617
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ static void CompliantMethod5(string[] args)
private bool Cond = new Random().Next() % 2 == 1;
}



class Repro2442
{
Expand Down Expand Up @@ -4033,4 +4033,26 @@ void Method()
}
Console.WriteLine(success);
}
}
}

// https://github.com/SonarSource/sonar-dotnet/issues/8570
class Repro_8570
{
void Method(int[] more)
{
var list = new List<int>();
list.AddRange(more);

if (list.Count == 0) // Noncompliant {{Change this condition so that it does not always evaluate to 'False'. Some code paths are unreachable.}}
// FP, we do not know if "more" is empty or not
{
Console.WriteLine(); // Secondary FP
}

if (list.Count() != 0) // Noncompliant {{Change this condition so that it does not always evaluate to 'True'.}}
// FP, we do not know if "more" is empty or not
{
Console.WriteLine();
}
}
}

0 comments on commit 6069617

Please sign in to comment.