-
Notifications
You must be signed in to change notification settings - Fork 16
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
Frame: decode payload length to return early [unverified] #24
Conversation
return Frame::PARTIAL; | ||
} | ||
|
||
// Finally decode the skipped parts of the header. | ||
bsl::memcpy(&frame->d_type, &buffer[0], sizeof(frame->d_type)); |
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.
Side effect: partial Frame
object will not be modified in any way during decode.
bdlb::BigEndianUint32 payloadLength; | ||
bsl::memcpy(&payloadLength, &buffer[3], sizeof(payloadLength)); | ||
|
||
if ((frameOverhead() + payloadLength) > bufferLen) { | ||
if (bufferLen < (frameOverhead() + payloadLength)) { |
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.
Turned from left to right, similar to line 65
if (bufferLen < frameOverhead()) { |
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.
LGTM
Signed-off-by: Evgeny Malygin <[email protected]>
f7ae7d3
to
5134cab
Compare
Closing this PR, the other PR contains the same changes with Verified status |
A small optimization for partial
Frame
s.I have a feeling though that it makes things a bit more complicated, especially addressing buffer via exact offsets like
buffer[3]
.Might be good to add
const size_t
constants for these offsets.