Repository navigation
fix: prevent digit position overflow in OctalToBinary for large octal inputs - #7776
Merged
alxkm merged 2 commits intoNov 24, 2026
Merged
Conversation
digitPosition grew as an int and overflowed for octal inputs with 5 or more digits, so convertOctalToBinary(10000) returned a negative value instead of 1000000000000. Making it a long keeps the position exact for the full range the method can represent.
Fails on the current implementation because digitPosition overflowed int; passes with the long fix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7776 +/- ##
============================================
- Coverage 82.45% 82.44% -0.01%
+ Complexity 8512 8509 -3
============================================
Files 847 847
Lines 26291 26291
Branches 5134 5134
============================================
- Hits 21677 21675 -2
Misses 3825 3825
- Partials 789 791 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Aditya2375
marked this pull request as ready for review
November 24, 2026 05:58
Aditya2375
requested review from
DenizAltunkapan,
alxkm and
yanglbme
as code owners
November 24, 2026 05:58
alxkm
approved these changes
Nov 24, 2026
alxkm
left a comment
Member
There was a problem hiding this comment.
Looks good. Thank you for the contribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
OctalToBinary.convertOctalToBinaryreturns wrong results for octal inputs with 5 or more digits.Why:
digitPositionis anintand gets multiplied by 1000 for every octal digit. At 10^12 it overflowsint(10^12 mod 2^32 = -727379968), soconvertOctalToBinary(10000)returned-727379968instead of1000000000000.Change: make
digitPositionalong(one line) and add a regression test covering 5- to 7-digit octal inputs. The new test fails on the current implementation and passes with this change; all existingOctalToBinaryTestcases still pass.clang-format -i --style=file path/to/your/file.java