Copr: Fix bugs of `exp_float_str_to_int_str`
@@ -915,7 +915,10 @@ fn exp_float_str_to_int_str<'a>(
}
// make `digits` immutable
let digits = digits;
- let exp: i64 = box_try!((&valid_float[(e_idx + 1)..]).parse::<i64>());
+ let exp = match valid_float[(e_idx + 1)..].parse::<i64>() {
+ Ok(exp) => exp,
+ _ => return Ok(Cow::Borrowed(valid_float)),
+ };
let (int_cnt, is_overflow): (i64, bool) = int_cnt.overflowing_add(exp);
if int_cnt > 21 || is_overflow {
// MaxInt64 has 19 decimal digits.
@@ -1197,6 +1200,28 @@ mod tests {
}
}
+ #[test]
+ fn test_bytes_to_int_overflow() {
+ let tests: Vec<(&[u8], _, _)> = vec![
+ (
+ b"12e1234817291749271847289417294",
+ FieldTypeTp::LongLong,
+ 9223372036854775807,
+ ),
+ (
+ b"12e1234817291749271847289417294",
+ FieldTypeTp::Long,
+ 2147483647,
+ ),
+ (b"12e1234817291749271847289417294", FieldTypeTp::Tiny, 127),
+ ];
+ let mut ctx = EvalContext::new(Arc::new(EvalConfig::from_flag(Flag::OVERFLOW_AS_WARNING)));
+ for (from, tp, to) in tests {
+ let r = from.to_int(&mut ctx, tp).unwrap();
+ assert_eq!(to, r);
+ }
+ }
+
#[test]
fn test_datatype_to_int_overflow() {
fn test_overflow<T: Debug + Clone + ToInt>(raw: T, dst: i64, tp: FieldTypeTp) {
