mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Matched on i64::checked_abs
and changed RuntimeError
to IntegerOverflow
This commit is contained in:
parent
84d47eb582
commit
f8c1828ddf
2 changed files with 6 additions and 10 deletions
|
@ -45,8 +45,8 @@ pub enum LimboError {
|
|||
ExtensionError(String),
|
||||
#[error("Unbound parameter at index {0}")]
|
||||
Unbound(NonZero<usize>),
|
||||
#[error("Runtime error: {0}")]
|
||||
RuntimeError(String),
|
||||
#[error("Runtime error: integer overflow")]
|
||||
IntegerOverflow,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
@ -2708,15 +2708,11 @@ pub fn exec_soundex(reg: &OwnedValue) -> OwnedValue {
|
|||
fn exec_abs(reg: &OwnedValue) -> Result<OwnedValue> {
|
||||
match reg {
|
||||
OwnedValue::Integer(x) => {
|
||||
if *x == i64::MIN {
|
||||
match i64::checked_abs(*x) {
|
||||
Some(y) => Ok(OwnedValue::Integer(y)),
|
||||
// Special case: if we do the abs of "-9223372036854775808", it causes overflow.
|
||||
// return RuntimeError
|
||||
return Err(LimboError::RuntimeError("integer overflow".to_string()));
|
||||
}
|
||||
if x < &0 {
|
||||
Ok(OwnedValue::Integer(-x))
|
||||
} else {
|
||||
Ok(OwnedValue::Integer(*x))
|
||||
// return IntegerOverflow error
|
||||
None => Err(LimboError::IntegerOverflow),
|
||||
}
|
||||
}
|
||||
OwnedValue::Float(x) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue