Copilot commented on code in PR #51169:
URL: https://github.com/apache/arrow/pull/51169#discussion_r3952477332


##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -962,9 +977,9 @@ Status SimpleDecimalFromString(const char* type_name, 
std::string_view s,
 
   if (out != nullptr) {
     uint64_t value{0};
-    ShiftAndAdd(dec.whole_digits, &value, 1);
-    ShiftAndAdd(dec.fractional_digits, &value, 1);
-    if (value > static_cast<uint64_t>(
+    if (ShiftAndAddWithOverflow(dec.whole_digits, &value, 1, dec.sign == '-') 
||
+        ShiftAndAddWithOverflow(dec.fractional_digits, &value, 1, dec.sign == 
'-') ||
+        value > static_cast<uint64_t>(
                     std::numeric_limits<typename 
DecimalClass::ValueType>::max())) {

Review Comment:
   `SimpleDecimalFromString` still rejects the smallest negative value for 
Decimal32/Decimal64 (e.g. -2^63) because it compares the parsed magnitude 
against `numeric_limits<...>::max()` regardless of sign. This is inconsistent 
with `ShiftAndAddWithOverflow(..., negative=true)`, which explicitly allows the 
`kSignBit` magnitude needed to represent INT_MIN/INT64_MIN, and it prevents 
parsing valid in-range values.



-- 
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]

Reply via email to