mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 18:24:20 +01:00
Fix remainder panic on zero right-hand-side
This commit is contained in:
@@ -897,17 +897,37 @@ pub fn exec_remainder(mut lhs: &OwnedValue, mut rhs: &OwnedValue) -> OwnedValue
|
||||
| (_, OwnedValue::Null)
|
||||
| (_, OwnedValue::Integer(0))
|
||||
| (_, OwnedValue::Float(0.0)) => OwnedValue::Null,
|
||||
(OwnedValue::Integer(lhs), OwnedValue::Integer(rhs)) => OwnedValue::Integer(lhs % rhs),
|
||||
(OwnedValue::Integer(lhs), OwnedValue::Integer(rhs)) => {
|
||||
if rhs == &0 {
|
||||
OwnedValue::Null
|
||||
} else {
|
||||
OwnedValue::Integer(lhs % rhs)
|
||||
}
|
||||
}
|
||||
(OwnedValue::Float(lhs), OwnedValue::Float(rhs)) => {
|
||||
OwnedValue::Float(((*lhs as i64) % (*rhs as i64)) as f64)
|
||||
let rhs_int = *rhs as i64;
|
||||
if rhs_int == 0 {
|
||||
OwnedValue::Null
|
||||
} else {
|
||||
OwnedValue::Float(((*lhs as i64) % rhs_int) as f64)
|
||||
}
|
||||
}
|
||||
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
|
||||
OwnedValue::Float(((*lhs as i64) % rhs) as f64)
|
||||
if rhs == &0 {
|
||||
OwnedValue::Null
|
||||
} else {
|
||||
OwnedValue::Float(((*lhs as i64) % rhs) as f64)
|
||||
}
|
||||
}
|
||||
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
|
||||
OwnedValue::Float((lhs % *rhs as i64) as f64)
|
||||
let rhs_int = *rhs as i64;
|
||||
if rhs_int == 0 {
|
||||
OwnedValue::Null
|
||||
} else {
|
||||
OwnedValue::Float((lhs % rhs_int) as f64)
|
||||
}
|
||||
}
|
||||
_ => todo!(),
|
||||
other => todo!("remainder not implemented for: {:?} {:?}", lhs, other),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,4 +159,9 @@ do_execsql_test select-like-expression {
|
||||
|
||||
do_execsql_test select-not-like-expression {
|
||||
select 'bar' not like 'bar%'
|
||||
} {0}
|
||||
} {0}
|
||||
|
||||
# regression test for float divisor being cast to zero int and panicking
|
||||
do_execsql_test select-like-expression {
|
||||
select 2 % 0.5
|
||||
} {}
|
||||
|
||||
Reference in New Issue
Block a user