You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/01/04 15:33:38 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #8955: ARROW-9948: [C++] in Decimal128::FromString raise when scale is out of bounds

pitrou commented on a change in pull request #8955:
URL: https://github.com/apache/arrow/pull/8955#discussion_r551388197



##########
File path: cpp/src/arrow/util/basic_decimal.cc
##########
@@ -949,33 +949,31 @@ DecimalStatus BasicDecimal128::Rescale(int32_t original_scale, int32_t new_scale
 
 void BasicDecimal128::GetWholeAndFraction(int scale, BasicDecimal128* whole,
                                           BasicDecimal128* fraction) const {
-  DCHECK_GE(scale, 0);
-  DCHECK_LE(scale, 38);
+  DCHECK_EQ(ValidateScale(scale), true);
 
   BasicDecimal128 multiplier(ScaleMultipliers[scale]);
   auto s = Divide(multiplier, whole, fraction);
   DCHECK_EQ(s, DecimalStatus::kSuccess);
 }
 
+bool BasicDecimal128::ValidateScale(int32_t scale) { return (std::abs(scale) <= 38); }

Review comment:
       Especially as `ScaleMultipliers` is then going to be indexed with a negative value above.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org