emmenlau commented on a change in pull request #2030:
URL: https://github.com/apache/thrift/pull/2030#discussion_r434488130
##########
File path: lib/cpp/src/thrift/transport/TBufferTransports.cpp
##########
@@ -361,16 +361,18 @@ void TMemoryBuffer::ensureCanWrite(uint32_t len) {
}
// Grow the buffer as necessary.
- uint64_t new_size = bufferSize_;
- while (len > avail) {
- new_size = new_size > 0 ? new_size * 2 : 1;
- if (new_size > maxBufferSize_) {
- throw TTransportException(TTransportException::BAD_ARGS,
- "Internal buffer size overflow");
- }
- avail = available_write() + (static_cast<uint32_t>(new_size) -
bufferSize_);
+ const uint32_t current_used = bufferSize_ - avail;
+ const uint32_t required_buffer_size = len + current_used;
Review comment:
It's one of my clean-code-quirks: I use `const` wherever possible. I
think it makes the code more robust, because none of these variables are
expected to change in the remainder of the code.
Would you prefer to remove my strong `const`ing? Then I will not continue to
use it in Thrift.
----------------------------------------------------------------
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]