diff options
-rw-r--r-- | javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java | 22 | ||||
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_message.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/compiler/plugin.pb.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/descriptor.pb.cc | 34 | ||||
-rw-r--r-- | src/google/protobuf/stubs/common.h | 2 |
5 files changed, 30 insertions, 32 deletions
diff --git a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java index b1b0c53a..322ada8e 100644 --- a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java +++ b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java @@ -33,6 +33,7 @@ package com.google.protobuf.nano; import java.io.IOException; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; /** @@ -61,6 +62,7 @@ public final class CodedOutputByteBufferNano { private CodedOutputByteBufferNano(final ByteBuffer buffer) { this.buffer = buffer; + this.buffer.order(ByteOrder.LITTLE_ENDIAN); } /** @@ -1038,24 +1040,20 @@ public final class CodedOutputByteBufferNano { /** Write a little-endian 32-bit integer. */ public void writeRawLittleEndian32(final int value) throws IOException { - writeRawByte((value ) & 0xFF); - writeRawByte((value >> 8) & 0xFF); - writeRawByte((value >> 16) & 0xFF); - writeRawByte((value >> 24) & 0xFF); + if (buffer.remaining() < 4) { + throw new OutOfSpaceException(buffer.position(), buffer.limit()); + } + buffer.putInt(value); } public static final int LITTLE_ENDIAN_32_SIZE = 4; /** Write a little-endian 64-bit integer. */ public void writeRawLittleEndian64(final long value) throws IOException { - writeRawByte((int)(value ) & 0xFF); - writeRawByte((int)(value >> 8) & 0xFF); - writeRawByte((int)(value >> 16) & 0xFF); - writeRawByte((int)(value >> 24) & 0xFF); - writeRawByte((int)(value >> 32) & 0xFF); - writeRawByte((int)(value >> 40) & 0xFF); - writeRawByte((int)(value >> 48) & 0xFF); - writeRawByte((int)(value >> 56) & 0xFF); + if (buffer.remaining() < 8) { + throw new OutOfSpaceException(buffer.position(), buffer.limit()); + } + buffer.putLong(value); } public static final int LITTLE_ENDIAN_64_SIZE = 8; diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 212fe2e1..af85919a 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -3510,7 +3510,7 @@ GenerateByteSize(io::Printer* printer) { } else { if (HasFieldPresence(descriptor_->file())) { printer->Print( - "if (_has_bits_[$index$ / 32] & $mask$) {\n", + "if (_has_bits_[$index$ / 32] & $mask$u) {\n", "index", SimpleItoa(i), "mask", SimpleItoa(mask)); printer->Indent(); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 344ed450..e7890fae 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -913,7 +913,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( int CodeGeneratorResponse_File::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 7) { + if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; if (has_name()) { total_size += 1 + diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 755c2617..fc13d8dc 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1648,7 +1648,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( int FileDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 3) { + if (_has_bits_[0 / 32] & 3u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -1664,7 +1664,7 @@ int FileDescriptorProto::ByteSize() const { } } - if (_has_bits_[9 / 32] & 3584) { + if (_has_bits_[9 / 32] & 3584u) { // optional .google.protobuf.FileOptions options = 8; if (has_options()) { total_size += 1 + @@ -2534,7 +2534,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( int DescriptorProto_ExtensionRange::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 3) { + if (_has_bits_[0 / 32] & 3u) { // optional int32 start = 1; if (has_start()) { total_size += 1 + @@ -2817,7 +2817,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( int DescriptorProto_ReservedRange::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 3) { + if (_has_bits_[0 / 32] & 3u) { // optional int32 start = 1; if (has_start()) { total_size += 1 + @@ -3373,7 +3373,7 @@ void DescriptorProto::SerializeWithCachedSizes( int DescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 129) { + if (_has_bits_[0 / 32] & 129u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -4558,7 +4558,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( int FieldDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 255) { + if (_has_bits_[0 / 32] & 255u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -5633,7 +5633,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( int EnumDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 5) { + if (_has_bits_[0 / 32] & 5u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -6102,7 +6102,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( int EnumValueDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 7) { + if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -6569,7 +6569,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( int ServiceDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 5) { + if (_has_bits_[0 / 32] & 5u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -7165,7 +7165,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( int MethodDescriptorProto::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 63) { + if (_has_bits_[0 / 32] & 63u) { // optional string name = 1; if (has_name()) { total_size += 1 + @@ -8240,7 +8240,7 @@ void FileOptions::SerializeWithCachedSizes( int FileOptions::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 255) { + if (_has_bits_[0 / 32] & 255u) { // optional string java_package = 1; if (has_java_package()) { total_size += 1 + @@ -8289,7 +8289,7 @@ int FileOptions::ByteSize() const { } } - if (_has_bits_[8 / 32] & 16128) { + if (_has_bits_[8 / 32] & 16128u) { // optional bool java_generic_services = 17 [default = false]; if (has_java_generic_services()) { total_size += 2 + 1; @@ -9279,7 +9279,7 @@ void MessageOptions::SerializeWithCachedSizes( int MessageOptions::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 15) { + if (_has_bits_[0 / 32] & 15u) { // optional bool message_set_wire_format = 1 [default = false]; if (has_message_set_wire_format()) { total_size += 1 + 1; @@ -9939,7 +9939,7 @@ void FieldOptions::SerializeWithCachedSizes( int FieldOptions::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 63) { + if (_has_bits_[0 / 32] & 63u) { // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; if (has_ctype()) { total_size += 1 + @@ -10498,7 +10498,7 @@ void EnumOptions::SerializeWithCachedSizes( int EnumOptions::ByteSize() const { int total_size = 0; - if (_has_bits_[0 / 32] & 3) { + if (_has_bits_[0 / 32] & 3u) { // optional bool allow_alias = 2; if (has_allow_alias()) { total_size += 1 + 1; @@ -12410,7 +12410,7 @@ void UninterpretedOption::SerializeWithCachedSizes( int UninterpretedOption::ByteSize() const { int total_size = 0; - if (_has_bits_[1 / 32] & 126) { + if (_has_bits_[1 / 32] & 126u) { // optional string identifier_value = 3; if (has_identifier_value()) { total_size += 1 + @@ -13248,7 +13248,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( int SourceCodeInfo_Location::ByteSize() const { int total_size = 0; - if (_has_bits_[2 / 32] & 12) { + if (_has_bits_[2 / 32] & 12u) { // optional string leading_comments = 3; if (has_leading_comments()) { total_size += 1 + diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 3acaeba1..e4c35a2f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -258,7 +258,7 @@ static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); #ifndef GOOGLE_PREDICT_FALSE #ifdef __GNUC__ // Provided at least since GCC 3.0. -#define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(!!(x), 1)) +#define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0)) #else #define GOOGLE_PREDICT_FALSE #endif |