util: Avoid invalid integer negation in FormatMoney and ValueFromAmount#20406
Conversation
|
I think something is wrong if such a large value is passed in the first place. But the code change looks correct to me anyhow. |
|
@laanwj I agree it should be rare, but there is at least one real world scenario where such an extreme value can be passed without it being a bug at the call site. In AFAICT we don't put a lower or upper bound on fee deltas (besides being Some additional context: #20383 (comment) :) |
|
I wasn't able to find a test that covered the negative COIN value scenarios. n % COIN |
61e6c03 to
abe78e8
Compare
|
@RandyMcMillan I'm not sure I can think of a scenario when the constant |
|
Thanks - I was just thinking thru different scenarios for testing. Negative moduli aren't something that comes up very often. :) |
f710c50 to
681e92c
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
681e92c to
8d9979e
Compare
|
Thanks. Code review ACK 8d9979e04afdb081d923f79b581586330968ff56 |
luke-jr
left a comment
There was a problem hiding this comment.
utACK, but... is there a reason we don't just leave the sign in quotient?
|
@luke-jr Do you mean in |
|
Right now, we're checking |
|
@luke-jr I'll let others chime in, and I'll happily adjust to the consensus opinion regarding the suggested extra refactoring :) |
8d9979e to
6043ae1
Compare
|
Thanks for reviewing! Nits addressed (+ rebase: sorry!). Please re-review :) |
|
When fuzzing the RPC interface I stumbled upon this case again: If anyone wants to test this PR vs The malformed JSON response can be found here. |
2662109 to
bd8926d
Compare
|
This PR has three stale ACKs (@laanwj, @MarcoFalke, @luke-jr) and I believe all feedback has been addressed. Anything left to do here? :) Would be nice to have this addressed to be able to fuzz direct and indirect callers of |
|
This PR has three stale ACKs and I believe all feedback has been addressed. Ready for merge after re-review? |
…(const CAmount& n) well-defined also when n is std::numeric_limits<CAmount>::min()
…omAmount(const CAmount& n) well-defined also when n is std::numeric_limits<CAmount>::min()
bd8926d to
1f05dbd
Compare
|
re-ACK 1f05dbd |
…ney and… … ValueFromAmount
Avoid invalid integer negation in
FormatMoneyandValueFromAmount.Fixes #20402.
Before this patch:
After this patch: