diff options
author | Adam Cozzette <acozzette@gmail.com> | 2017-12-08 13:34:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-08 13:34:56 -0800 |
commit | a426833d1a64e23df69775d1abe5b87a2ea6bfdb (patch) | |
tree | deba72b382f6f0715bb00525a81f2efb5d5abb3a | |
parent | 9b09a2af148044b5a0fd4c689430ffa63b8e2489 (diff) | |
parent | 24493eef9395e5b832360e12efabf9c363c9cb15 (diff) | |
download | protobuf-a426833d1a64e23df69775d1abe5b87a2ea6bfdb.tar.gz protobuf-a426833d1a64e23df69775d1abe5b87a2ea6bfdb.tar.bz2 protobuf-a426833d1a64e23df69775d1abe5b87a2ea6bfdb.zip |
Merge pull request #4000 from Kwizatz/master
Using binary one's complement to negate an unsigned int
-rw-r--r-- | src/google/protobuf/wire_format_lite.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index 265f5f93..76275518 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -860,7 +860,7 @@ inline uint32 WireFormatLite::ZigZagEncode32(int32 n) { inline int32 WireFormatLite::ZigZagDecode32(uint32 n) { // Note: Using unsigned types prevent undefined behavior - return static_cast<int32>((n >> 1) ^ -(n & 1)); + return static_cast<int32>((n >> 1) ^ (~(n & 1) + 1)); } inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { @@ -871,7 +871,7 @@ inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { inline int64 WireFormatLite::ZigZagDecode64(uint64 n) { // Note: Using unsigned types prevent undefined behavior - return static_cast<int64>((n >> 1) ^ -(n & 1)); + return static_cast<int64>((n >> 1) ^ (~(n & 1) + 1)); } // String is for UTF-8 text only, but, even so, ReadString() can simply |