[
https://issues.apache.org/jira/browse/AVRO-2717?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17314187#comment-17314187
]
Thiruvalluvan M. G. commented on AVRO-2717:
-------------------------------------------
Essentially, the fix here is to replace `((input << 1) ^ (input >> 31))` with
`((uint32_t(input) << 1) ^ (input >> 31))` and similar for 64 bit numbers. But
bitwise shift-left operation produces exactly the same result irrespective of
whether it is signed or unsigned integer. Shift-right has different behavior
because of sign-extension.
It is not clear why we need this change. In fact both the versions compile into
identical assembly as can seen here: https://godbolt.org/z/7je6K945M
> Fix undefined behaviour in ZigZag encoding if Avro was compiled with the C++
> standard less than C++20.
> ------------------------------------------------------------------------------------------------------
>
> Key: AVRO-2717
> URL: https://issues.apache.org/jira/browse/AVRO-2717
> Project: Apache Avro
> Issue Type: Improvement
> Components: c++
> Reporter: Aleksei
> Priority: Minor
>
> The fix is here:
> [https://github.com/apache/avro/compare/master...ClickHouse-Extras:master]
> It is found while testing with UBSan here:
> [https://github.com/ClickHouse/ClickHouse/pull/8717]
> For further info look here:
> [https://en.cppreference.com/w/cpp/language/operator_arithmetic]
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)