fallintoplace commented on code in PR #755:
URL: https://github.com/apache/iceberg-cpp/pull/755#discussion_r3435469822
##########
src/iceberg/util/truncate_util.h:
##########
@@ -84,7 +86,15 @@ class ICEBERG_EXPORT TruncateUtils {
template <typename T>
requires std::is_same_v<T, int32_t> || std::is_same_v<T, int64_t>
static inline T TruncateInteger(T v, int32_t W) {
- return v - (((v % W) + W) % W);
Review Comment:
Yep, the formula is from the spec. The issue is not the spec math, but
evaluating it with signed C++ integer types. For int32_t, (v % W) + W can
overflow when W is large. For int64_t, the final v - remainder can overflow at
INT64_MIN. The wider type keeps the spec formula while avoiding signed UB.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]