Skip to content

Fix integer overflow in AbsoluteValue.getAbsValue for Integer.MIN_VALUE - #7604

Open
arsam4waffels wants to merge 1 commit into
TheAlgorithms:masterfrom
arsam4waffels:fix/absolute-value-overflow
Open

Fix integer overflow in AbsoluteValue.getAbsValue for Integer.MIN_VALUE#7604
arsam4waffels wants to merge 1 commit into
TheAlgorithms:masterfrom
arsam4waffels:fix/absolute-value-overflow

Conversation

@arsam4waffels

Copy link
Copy Markdown
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Problem

Math.abs(Integer.MIN_VALUE) returns Integer.MIN_VALUE due to overflow,
since 2,147,483,648 exceeds the int range.

Fix

Changed parameter and return type from int to long to handle this edge case correctly.

Test

Updated testMinIntEdgeCase to verify correct behavior.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.10%. Comparing base (c99b056) to head (370327f).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7604      +/-   ##
============================================
- Coverage     81.12%   81.10%   -0.02%     
+ Complexity     7816     7814       -2     
============================================
  Files           827      827              
  Lines         24742    24742              
  Branches       4833     4833              
============================================
- Hits          20072    20068       -4     
- Misses         3906     3907       +1     
- Partials        764      767       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants