You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2024/02/19 09:03:09 UTC

(avro) branch main updated: AVRO-2717: Fix UB in ZigZag encoding (pre C++-20) (#2744)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/main by this push:
     new 071db199b AVRO-2717: Fix UB in ZigZag encoding (pre C++-20) (#2744)
071db199b is described below

commit 071db199b28dc0d06b0f4cfc2c81504efd04a51d
Author: Mikhail Koviazin <mi...@aiven.io>
AuthorDate: Mon Feb 19 11:03:03 2024 +0200

    AVRO-2717: Fix UB in ZigZag encoding (pre C++-20) (#2744)
---
 lang/c++/api/Zigzag.hh | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lang/c++/api/Zigzag.hh b/lang/c++/api/Zigzag.hh
index fefdc3f32..5d20e028b 100644
--- a/lang/c++/api/Zigzag.hh
+++ b/lang/c++/api/Zigzag.hh
@@ -30,16 +30,14 @@
 namespace avro {
 
 AVRO_DECL constexpr uint64_t encodeZigzag64(int64_t input) noexcept {
-    // cppcheck-suppress shiftTooManyBitsSigned
-    return ((input << 1) ^ (input >> 63));
+    return ((static_cast<uint64_t>(input) << 1) ^ (input >> 63));
 }
 AVRO_DECL constexpr int64_t decodeZigzag64(uint64_t input) noexcept {
     return static_cast<int64_t>(((input >> 1) ^ -(static_cast<int64_t>(input) & 1)));
 }
 
 AVRO_DECL constexpr uint32_t encodeZigzag32(int32_t input) noexcept {
-    // cppcheck-suppress shiftTooManyBitsSigned
-    return ((input << 1) ^ (input >> 31));
+    return (static_cast<uint32_t>(input) << 1) ^ (input >> 31);
 }
 AVRO_DECL constexpr int32_t decodeZigzag32(uint32_t input) noexcept {
     return static_cast<int32_t>(((input >> 1) ^ -(static_cast<int64_t>(input) & 1)));