cfriedt commented on a change in pull request #2007:
URL: https://github.com/apache/thrift/pull/2007#discussion_r443396568
##########
File path: lib/cpp/src/thrift/transport/TBufferTransports.h
##########
@@ -587,11 +587,9 @@ class TMemoryBuffer : public
TVirtualTransport<TMemoryBuffer, TBufferBase> {
void resetBuffer() {
rBase_ = buffer_;
rBound_ = buffer_;
- wBase_ = buffer_;
- // It isn't safe to write into a buffer we don't own.
- if (!owner_) {
- wBound_ = wBase_;
- bufferSize_ = 0;
+ if (owner_) {
+ wBase_ = buffer_;
+ wBound_ = buffer_ + bufferSize_;
Review comment:
If the buffer is not owned (is read-only, i.e. was created with `policy
== OBSERVE`), `wBase_` is initialized to `wBase_ = buffer_ + wPos` (the end of
the buffer) inside of `initCommon()` and never updated.
Throughout the lifetime of the buffer, if it is not owned (read-only),
`wBound_ == wBase_`, meaning there is no space to write (both `wBound_` and
`wBase_` continue to point at the end of the buffer).
Only if the buffer is owned (writeable) should `wbase_` and `wbound_` be
reset to the beginning / end of the buffer, in `resetBuffer()`.
I agree, the current implementation is a bit confusing and it might be
possible to rewrite it to be more obvious. This change realizes the intent of
the design while keeping changes to the implementation minimal.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]