Copilot commented on code in PR #51169:
URL: https://github.com/apache/arrow/pull/51169#discussion_r3952503516
##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -895,9 +907,12 @@ Status DecimalFromString(const char* type_name,
std::string_view s, Decimal* out
if (out != nullptr) {
static_assert(Decimal::kBitWidth % 64 == 0, "decimal bit-width not a
multiple of 64");
std::array<uint64_t, Decimal::kBitWidth / 64> little_endian_array{};
- ShiftAndAdd(dec.whole_digits, little_endian_array.data(),
little_endian_array.size());
- ShiftAndAdd(dec.fractional_digits, little_endian_array.data(),
- little_endian_array.size());
+ if (ShiftAndAddWithOverflow(dec.whole_digits, little_endian_array.data(),
+ little_endian_array.size(), dec.sign == '-') ||
+ ShiftAndAddWithOverflow(dec.fractional_digits,
little_endian_array.data(),
+ little_endian_array.size(), dec.sign == '-')) {
+ return Status::Invalid("The string '", s, "' cannot be represented as ",
type_name);
+ }
Review Comment:
Overflow validation is only performed when `out != nullptr`. Calling
`FromString` with `out == nullptr` (but requesting `precision`/`scale`) would
still return `OK` for values that cannot be represented in the target bit
width, which is inconsistent with the new overflow-rejection behavior.
This issue also appears on line 978 of the same file.
--
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]