Skip to content

[SIL.WIndows.Forms] In CustomDropDown, fixed timer check #1433

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

imnasnainaec
Copy link
Contributor

@imnasnainaec imnasnainaec commented May 22, 2025

If you start with double 0 and add .1 ten times, you can end up with (e.g.) 0.9999999999999999 instead of 1f.

This fixes https://github.com/sillsdev/libpalaso/security/code-scanning/2627

Of the other 14 warnings for "Equality check on floating point values" (https://github.com/sillsdev/libpalaso/security/code-scanning?query=is%3Aopen+branch%3Amaster+rule%3Acs%2Fequality-on-floats), three involve screen DPI (2624, 2625, 2626), and the rest involve font size.


This change is Reviewable

@imnasnainaec imnasnainaec self-assigned this May 22, 2025
@imnasnainaec imnasnainaec changed the title +semver:patch [SIL.WIndows.Forms] In CustomDropDown, fixed timer check \\\[SIL.WIndows.Forms] In CustomDropDown, fixed timer check May 22, 2025
@imnasnainaec imnasnainaec changed the title \\\[SIL.WIndows.Forms] In CustomDropDown, fixed timer check [SIL.WIndows.Forms] In CustomDropDown, fixed timer check May 22, 2025
Copy link

github-actions bot commented May 22, 2025

Palaso Tests

     4 files  ±0       4 suites  ±0   11m 11s ⏱️ +56s
 4 978 tests ±0   4 743 ✅  - 1  235 💤 +1  0 ❌ ±0 
16 186 runs  ±0  15 481 ✅  - 2  705 💤 +2  0 ❌ ±0 

Results for commit d9cc485. ± Comparison against base commit 23dc405.

This pull request skips 1 test.
SIL.Tests.IO.FileLocationUtilitiesTests ‑ LocateInProgramFiles_SendValidProgramDeepSearch_SubFolderSpecified_ReturnsProgramPath

♻️ This comment has been updated with latest results.

Copy link
Contributor

@tombogle tombogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2, all commit messages.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @imnasnainaec)


SIL.Windows.Forms/Widgets/CustomDropDown.cs line 187 at r2 (raw file):

			{
				Opacity += 0.1;
				if (Opacity > .99)

Should we also actually force opacity to be 1f? In practice, I imagine it won't make a noticeable difference (maybe not any difference), so maybe this is just me feeling angst over the imprecision.

@imnasnainaec imnasnainaec requested a review from tombogle May 27, 2025 20:35
Comment on lines +187 to +188
if (Opacity > .99)
Opacity = 1f;

Check warning

Code scanning / CodeQL

Misleading indentation Warning

Missing braces? Inspect indentation of
the control flow successor
.

Copilot Autofix

AI 12 minutes ago

To fix the problem, we will add braces {} around the body of the if statement on line 187. This ensures that the scope of the if statement is explicit and matches the indentation. The braces will clarify that Opacity = 1f; is conditionally executed, while timer.Stop(); is always executed after the if statement. No additional imports, methods, or definitions are required for this fix.


Suggested changeset 1
SIL.Windows.Forms/Widgets/CustomDropDown.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SIL.Windows.Forms/Widgets/CustomDropDown.cs b/SIL.Windows.Forms/Widgets/CustomDropDown.cs
--- a/SIL.Windows.Forms/Widgets/CustomDropDown.cs
+++ b/SIL.Windows.Forms/Widgets/CustomDropDown.cs
@@ -187,4 +187,6 @@
 				if (Opacity > .99)
+				{
 					Opacity = 1f;
-					timer.Stop();
+				}
+				timer.Stop();
 			};
EOF
@@ -187,4 +187,6 @@
if (Opacity > .99)
{
Opacity = 1f;
timer.Stop();
}
timer.Stop();
};
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants