sonar-dotnet
sonar-dotnet copied to clipboard
NET-1692 Fix S3949 FP: Unchecked keyword is sometimes ignored
Description
S3949 is supposed to not trigger when the unchecked keyword is present in the method containing the potential issue location. In some cases this exception is ignored.
Repro steps
void Foo1()
{
_ = 1 + 1;
unchecked
{
var i = int.MaxValue;
_ = i + 1; // Noncompliant FP
}
}
Related information
The bug is caused by faulty logic in the ShouldExecute implementation. If the visitor finds a risky operation (setting HasOverflow true) it will stop execution and not find unchecked keywords following in later nodes.
@Tim-Pohlmann I think this issues can be closed. The code you linked to looks completely different now and there are a lot of test cases which seem to be written exactly for such cases.
Internal ticket NET-1692