diff options
Diffstat (limited to 'src/google/protobuf/io/zero_copy_stream_impl_lite.cc')
-rw-r--r-- | src/google/protobuf/io/zero_copy_stream_impl_lite.cc | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index 58aff0e..e801251 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// http://code.google.com/p/protobuf/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -32,13 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include <google/protobuf/io/zero_copy_stream_impl_lite.h> - -#include <algorithm> -#include <limits> - +#include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/stubs/common.h> -#include <google/protobuf/stubs/stl_util.h> +#include <google/protobuf/stubs/stl_util-inl.h> namespace google { namespace protobuf { @@ -163,23 +159,15 @@ bool StringOutputStream::Next(void** data, int* size) { // without a memory allocation this way. STLStringResizeUninitialized(target_, target_->capacity()); } else { - // Size has reached capacity, try to double the size. - if (old_size > std::numeric_limits<int>::max() / 2) { - // Can not double the size otherwise it is going to cause integer - // overflow in the expression below: old_size * 2 "; - GOOGLE_LOG(ERROR) << "Cannot allocate buffer larger than kint32max for " - << "StringOutputStream."; - return false; - } - // Double the size, also make sure that the new size is at least - // kMinimumSize. + // Size has reached capacity, so double the size. Also make sure + // that the new size is at least kMinimumSize. STLStringResizeUninitialized( target_, max(old_size * 2, kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness. } - *data = mutable_string_data(target_) + old_size; + *data = string_as_array(target_) + old_size; *size = target_->size() - old_size; return true; } |