Validate deque capacity before allocation - #87
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 958fb4e7db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Закрываю как superseded by #116: изменения перенесены в одну проверенную ветку, все review findings учтены; локальный mvn verify прошёл полностью. |



Motivation
new int[cap], allowingNegativeArraySizeExceptionfor negative input andOutOfMemoryErrorfor very large input.Description
MAX_CAPACITYbound (100_000) and asafeCapacity(int)helper to normalize capacities before allocation insrc/main/java/algorithms/sprint2/Deque.java.new int[cap]withnew int[this.cap]wherethis.capis the sanitized value returned bysafeCapacity.0and cap excessively large capacities toMAX_CAPACITYto avoid allocating uncontrolled memory.erroroutputs instead of crashing.Testing
javac -d /tmp/deque-classes src/main/java/algorithms/sprint2/Deque.javaand the compilation succeeded.java -Dos.name=Windows -cp /tmp/deque-classes algorithms.sprint2.Dequewhich printedTest OK, indicating existing tests pass.1\n-1\npop_front\nand0\n1000000000\nto the program (the latter with-Xmx32m) and observed controllederroroutputs withoutNegativeArraySizeExceptionorOutOfMemoryError, confirming the fix.Codex Task