Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/1214#discussion_r106795259
--- Diff: lib/cpp/src/thrift/protocol/TCompactProtocol.tcc ---
@@ -387,7 +389,11 @@ uint32_t
TCompactProtocolT<Transport_>::writeVarint64(uint64_t n) {
*/
template <class Transport_>
uint64_t TCompactProtocolT<Transport_>::i64ToZigzag(const int64_t l) {
- return (l << 1) ^ (l >> 63);
+ const int64_t m = l >> 63;
+ uint64_t p, q;
+ memcpy(&p, &l, sizeof(p));
+ memcpy(&q, &m, sizeof(q));
+ return p = (p << 1) ^ q;
--- End diff --
`return (static_cast<uint64_t>(l) << 1) ^ (l >> 63);` would be much simpler
and efficient.
static casting of negative to unsigned value is well defined AFAICT.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---