diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2018-01-31 11:59:57 -0500 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-01-31 12:36:54 -0500 |
commit | 953adb16ff2f982d54dd812b51df5fdb392732f8 (patch) | |
tree | f6a855939173eaf8a5a4d6bfc84a87fff8255a0e /objectivec/GPBUtilities_PackagePrivate.h | |
parent | b718551571983f281d065e818da4fd9ca5723d89 (diff) | |
download | protobuf-953adb16ff2f982d54dd812b51df5fdb392732f8.tar.gz protobuf-953adb16ff2f982d54dd812b51df5fdb392732f8.tar.bz2 protobuf-953adb16ff2f982d54dd812b51df5fdb392732f8.zip |
Add casts to removed undefined behaviors around shifts.
Fixes #4246
Fixes #4247
Diffstat (limited to 'objectivec/GPBUtilities_PackagePrivate.h')
-rw-r--r-- | objectivec/GPBUtilities_PackagePrivate.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/objectivec/GPBUtilities_PackagePrivate.h b/objectivec/GPBUtilities_PackagePrivate.h index c8b21ed7..ed424ce3 100644 --- a/objectivec/GPBUtilities_PackagePrivate.h +++ b/objectivec/GPBUtilities_PackagePrivate.h @@ -124,7 +124,7 @@ GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) { // thus always taking 10 bytes on the wire.) GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) { // Note: the right-shift must be arithmetic - return (uint32_t)((n << 1) ^ (n >> 31)); + return ((uint32_t)n << 1) ^ (uint32_t)(n >> 31); } // Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers @@ -133,7 +133,7 @@ GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) { // thus always taking 10 bytes on the wire.) GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) { // Note: the right-shift must be arithmetic - return (uint64_t)((n << 1) ^ (n >> 63)); + return ((uint64_t)n << 1) ^ (uint64_t)(n >> 63); } #pragma clang diagnostic push |