diff options
author | Jozef Izso <jozef.izso@gmail.com> | 2018-04-27 21:15:17 +0200 |
---|---|---|
committer | Jozef Izso <jozef.izso@gmail.com> | 2018-04-27 21:15:17 +0200 |
commit | 8a603ec41180085424d90a7913b4ffaaddb26774 (patch) | |
tree | 1545b87e0f844f70ab04e75a1640c7e1d9285cba | |
parent | 2131584b8d31c35cc7c7a7b3c54704898d15dad8 (diff) | |
download | protobuf-8a603ec41180085424d90a7913b4ffaaddb26774.tar.gz protobuf-8a603ec41180085424d90a7913b4ffaaddb26774.tar.bz2 protobuf-8a603ec41180085424d90a7913b4ffaaddb26774.zip |
Using binary one's complement to negate an unsigned int
This removes a Visual Studio warning C4146: unary minus operator applied to unsigned type, result still unsigned.
Original code: https://github.com/google/protobuf/commit/24493eef9395e5b832360e12efabf9c363c9cb15
-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 |