CalculationsShouldNotOverflow.SyntaxKindWalker reduce allocations and evaluations in the hot path #8103
Labels
Area: C#
C# rules related issues.
Area: CFG/SE
CFG and SE related issues.
Type: False Negative
Rule is NOT triggered when it should be.
Projects
Milestone
There are two things wrong with the walker:
sonar-dotnet/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/CalculationsShouldNotOverflow.cs
Lines 50 to 65 in ba33020
Flawed logic
IsUnchecked is reset too early here/at the wrong position or the IsUnchecked field is not needed at all. It should be reset after the unchecked block more like so:
Nested checked/unchecked blocks are potentially wrong (for this to work, IsUnchecked must be a counter).
Array allocation in the hot path
Visit is performance-sensitive and allocates a params array on each invocation. The IsAnyKind should be replaced by a
node.Kind() is SyntaxKind.AddExpression or SyntaxKind.AddAssignmentExpression or ...
expression:Also affected:
The text was updated successfully, but these errors were encountered: