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 FP: Should not raise on double condition #8470

Closed
nrankin18 opened this issue Dec 14, 2023 · 1 comment · Fixed by #8475
Closed

Fix S2583 FP: Should not raise on double condition #8470

nrankin18 opened this issue Dec 14, 2023 · 1 comment · Fixed by #8475
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@nrankin18
Copy link

nrankin18 commented Dec 14, 2023

Description

Rule S2583 does not correctly identify all possible values of a double and incorrectly assumes a double cannot fall between (0, 1).

Repro steps

double t = 0.5;
if (t <= 0) {
	return "a";
}

if (t >= 1) {  // S2583 is flagged. Assumes t must be >= 1
	return "b";
}

return "c";

Expected behavior

The issue should not be flagged since t can be (0, 1).

Actual behavior

S2583 is flagged.

Known workarounds

Please provide a description of any known workarounds.

Related information

  • C# version: 10.0
  • Visual Studio version: 17.8.2
  • dotnet version : net6.0
  • Operating System: Windows 11 Home 10.0.22000 Build 22000
@pavel-mikula-sonarsource
Copy link
Contributor

Hi,

Thank you for reporting this case, I confirm it as FP. It's an interesting one, as we should not be tracking double type here.

@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S2583 FP/FN: False positive evaluating unreachable code Fix S2583 FP: Should not raise on double type Dec 15, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S2583 FP: Should not raise on double type Fix S2583 FP: Should not raise on double condition Dec 15, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. Sprint: SE labels Dec 15, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 9.16 milestone Dec 15, 2023
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: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants