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

Fix S2583/S2589 FN: try-catch in loop, LVA purges symbol prematurely #8719

Closed
Tim-Pohlmann opened this issue Feb 8, 2024 · 0 comments · Fixed by #9449
Closed

Fix S2583/S2589 FN: try-catch in loop, LVA purges symbol prematurely #8719

Tim-Pohlmann opened this issue Feb 8, 2024 · 0 comments · Fixed by #9449
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Milestone

Comments

@Tim-Pohlmann
Copy link
Contributor

Tim-Pohlmann commented Feb 8, 2024

void Test(bool condition1, bool condition2)
{
    var success = false;
    Exception exception = null;
    int retries = 0;
    while (!success && retries < 5) // Noncompliant TP
    {
        exception = null;
        try
        {
            Console.WriteLine();
            success = true;
        }
        catch (Exception e)
        {
            exception = e;
        }
    }
    if (exception != null)  // FN!
    {
        Console.WriteLine(exception);
    }
    Console.WriteLine(success);
}

The SymbolicValue for success gets lost when entering the try-block.

@Tim-Pohlmann Tim-Pohlmann added Type: False Negative Rule is NOT triggered when it should be. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Feb 8, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 9, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 13, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 13, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 13, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 13, 2024
Tim-Pohlmann added a commit that referenced this issue Feb 14, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.28 milestone Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants