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: keep odd number checks using modulus, however, make sure they wi… #5653

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

firefly2442
Copy link
Contributor

…ll work for negative numbers as well, found via SpotBugs

Check for oddness that won't work for negative numbers The code uses x % 2 == 1 to check to see if a value is odd, but this won't work for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check for oddness, consider using (x & 1) == 1, or x % 2 != 0.

Bug kind and pattern: IM - IM_BAD_CHECK_FOR_ODD

This should keep all the logic the same, just prevent this from being flagged in SpotBugs or other code checkers.

…ll work for negative numbers as well, found via SpotBugs

Check for oddness that won't work for negative numbers
The code uses x % 2 == 1 to check to see if a value is odd, but this won't work for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check for oddness, consider using (x & 1) == 1, or x % 2 != 0.

Bug kind and pattern: IM - IM_BAD_CHECK_FOR_ODD
@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 10.02%. Comparing base (8dbf74b) to head (be04339).
Report is 26 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5653      +/-   ##
============================================
- Coverage     10.02%   10.02%   -0.01%     
+ Complexity     6069     6067       -2     
============================================
  Files          1074     1074              
  Lines        141609   141598      -11     
  Branches      20646    20645       -1     
============================================
- Hits          14203    14201       -2     
+ Misses       126032   126024       -8     
+ Partials       1374     1373       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HammerGS HammerGS merged commit 12f50d0 into MegaMek:master Jan 5, 2025
4 checks passed
@firefly2442 firefly2442 deleted the spotbugs-odd-check branch January 5, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants