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 S2259: "Null pointer dereference" raises FP when a variable is initialized in catch(Exception) block #493

Closed
valhristov opened this issue Jun 29, 2017 · 1 comment
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@valhristov
Copy link
Contributor

object o = null;
try
{
    o = new object();
    // do something
}
catch
{
    o = new object();
}
return o.ToString(); // FP is detected

TIP: The CFG has connection between the beginning of the try block and its end for the cases when a potential exception is not caught. However, catch or catch(Exception) will catch all exceptions, meaning that the connection is not needed in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

3 participants