Clarify the safety of NetClock::time_point arithmetic: #3787
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.
used with subtraction.
High Level Overview of Change
To address #3656 a comprehensive survey of all uses of
NetClock::time_point
in rippled was made. Only two minor were found.This is the expression #3656 refers to as being vulnerable to unsigned overflow. However it turns out this expression is fine because
p.validationCURRENT_EARLY
is a 64 bit signed integral type. Thus the 32 but unsignednow
is losslessly converted to signed 64 bit prior to the conversion. Additionally the 32 but unsignedsignTime
is converted to signed 64 bit prior to the comparison.The expression is correct and bullet-proof as is. A comment to this effect has been added.
While correct, using explicit conversion syntax for implicit construction is error-prone because one might accidentally choose an unwanted explicit constructor. This code is safer using implicit syntax to ensure that only an implicit constructor is chosen:
NetClock::time_point const when = ctx_.view().parentCloseTime();