diff options
author | Rodrigo Hernandez <kwizatz@aeongames.com> | 2017-12-04 19:04:42 -0600 |
---|---|---|
committer | Rodrigo Hernandez <kwizatz@aeongames.com> | 2017-12-07 13:29:20 -0600 |
commit | 24493eef9395e5b832360e12efabf9c363c9cb15 (patch) | |
tree | 2679b782765de92262e3025d3f9b65dfe4f7f449 | |
parent | db7c043f6dce400e4c777810a76fe900a7f0bc7e (diff) | |
download | protobuf-24493eef9395e5b832360e12efabf9c363c9cb15.tar.gz protobuf-24493eef9395e5b832360e12efabf9c363c9cb15.tar.bz2 protobuf-24493eef9395e5b832360e12efabf9c363c9cb15.zip |
Using binary one's complement to negate an unsigned int
This removes a Visual Studio warning:
warning C4146: unary minus operator applied to unsigned type, result
still unsigned.
-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 cf614c02..361920b8 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 |