aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2018-04-27 12:19:24 -0700
committerGitHub <noreply@github.com>2018-04-27 12:19:24 -0700
commitfe773bfe97854c4be95b1b6e66281c0868194269 (patch)
tree1545b87e0f844f70ab04e75a1640c7e1d9285cba
parent2131584b8d31c35cc7c7a7b3c54704898d15dad8 (diff)
parent8a603ec41180085424d90a7913b4ffaaddb26774 (diff)
downloadprotobuf-fe773bfe97854c4be95b1b6e66281c0868194269.tar.gz
protobuf-fe773bfe97854c4be95b1b6e66281c0868194269.tar.bz2
protobuf-fe773bfe97854c4be95b1b6e66281c0868194269.zip
Merge pull request #4572 from jozefizso/fix/4494_compilation_error_c4146
Using binary one's complement to negate an unsigned int
-rw-r--r--src/google/protobuf/wire_format_lite.h4
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