-
-
Notifications
You must be signed in to change notification settings - Fork 369
Enhance getusedcoinstagstxhashes to handle edge cases #1775
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
base: master
Are you sure you want to change the base?
Conversation
Added a check to ensure that the startNumber does not exceed the available elements in the tags vector. This prevents potential out-of-bounds access and improves the robustness of the function.
WalkthroughThe PR modifies Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the Have feedback? Share your thoughts on our Discord thread! Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/rpc/misc.cpp`:
- Around line 1602-1609: The code casts startNumber to size_t causing huge
values for negative inputs; before casting, guard against negatives by clamping
startNumber to zero (or return an RPC error) and then compute skip from the
non-negative value; e.g., check if startNumber < 0 and set a signed temporary to
0 (or reject) and then set size_t skip =
static_cast<size_t>(that_non_negative_value) before comparing with tags.size();
update the logic around startNumber, skip and the for-loop that uses tags to use
this clamped/validated value.
- Around line 1602-1609: The pagination logic in getusedcoinstagstxhashes is
inverted: instead of skipping the last startNumber elements like
getusedcoinstags, it currently skips the first ones; update the loop to use the
same end-based pagination used by getusedcoinstags (refer to the logic at
getusedcoinstags) by replacing the current skip/iteration approach with the
check used there (e.g., inside the loop use if (cmp::less((tags.size() - i - 1),
startNumber)) continue;) so the method skips newest tags and returns the same
slice semantics as getusedcoinstags.
No description provided.