Index: third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h |
diff --git a/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h b/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h |
index 144f44f0635304bd7acc72ae628eab2d0a1998d3..d95b06e04e5310d25eb4294959bacd2479933e2f 100644 |
--- a/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h |
+++ b/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -36,7 +36,10 @@ |
#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ |
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_INL_H__ |
+#include <google/protobuf/stubs/logging.h> |
+#include <google/protobuf/stubs/common.h> |
#include <google/protobuf/io/coded_stream.h> |
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h> |
#include <string> |
#include <google/protobuf/stubs/stl_util.h> |
@@ -50,10 +53,12 @@ inline bool CodedInputStream::InternalReadStringInline(string* buffer, |
if (BufferSize() >= size) { |
STLStringResizeUninitialized(buffer, size); |
- // When buffer is empty, string_as_array(buffer) will return NULL but memcpy |
- // requires non-NULL pointers even when size is 0. Hench this check. |
- if (size > 0) { |
- memcpy(string_as_array(buffer), buffer_, size); |
+ std::pair<char*, bool> z = as_string_data(buffer); |
+ if (z.second) { |
+ // Oddly enough, memcpy() requires its first two args to be non-NULL even |
+ // if we copy 0 bytes. So, we have ensured that z.first is non-NULL here. |
+ GOOGLE_DCHECK(z.first != NULL); |
+ memcpy(z.first, buffer_, size); |
Advance(size); |
} |
return true; |
@@ -62,6 +67,23 @@ inline bool CodedInputStream::InternalReadStringInline(string* buffer, |
return ReadStringFallback(buffer, size); |
} |
+inline bool CodedInputStream::InternalReadRawInline(void* buffer, int size) { |
+ int current_buffer_size; |
+ while ((current_buffer_size = BufferSize()) < size) { |
+ // Reading past end of buffer. Copy what we have, then refresh. |
+ memcpy(buffer, buffer_, current_buffer_size); |
+ buffer = reinterpret_cast<uint8*>(buffer) + current_buffer_size; |
+ size -= current_buffer_size; |
+ Advance(current_buffer_size); |
+ if (!Refresh()) return false; |
+ } |
+ |
+ memcpy(buffer, buffer_, size); |
+ Advance(size); |
+ |
+ return true; |
+} |
+ |
} // namespace io |
} // namespace protobuf |
} // namespace google |