Do not check for data oversize when unchecked.
This commit is contained in:
parent
a417bdd8e3
commit
fcb5059570
@ -29,24 +29,27 @@ fn pad<T: Variant + Clone>(engine: &Engine, args: &mut [&mut Dynamic]) -> FuncRe
|
||||
let len = *args[1].downcast_ref::<INT>().unwrap();
|
||||
|
||||
// Check if array will be over max size limit
|
||||
if engine.max_array_size > 0 && len > 0 && (len as usize) > engine.max_array_size {
|
||||
Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Size of array".to_string(),
|
||||
engine.max_array_size,
|
||||
len as usize,
|
||||
Position::none(),
|
||||
)))
|
||||
} else if len >= 0 {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
if engine.max_array_size > 0 && len > 0 && (len as usize) > engine.max_array_size {
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Size of array".to_string(),
|
||||
engine.max_array_size,
|
||||
len as usize,
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
if len >= 0 {
|
||||
let item = args[2].downcast_ref::<T>().unwrap().clone();
|
||||
let list = args[0].downcast_mut::<Array>().unwrap();
|
||||
|
||||
while list.len() < len as usize {
|
||||
push(list, item.clone())?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
macro_rules! reg_op {
|
||||
|
@ -222,32 +222,35 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
||||
let len = *args[1].downcast_ref::< INT>().unwrap();
|
||||
|
||||
// Check if string will be over max size limit
|
||||
if engine.max_string_size > 0 && len > 0 && (len as usize) > engine.max_string_size {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
if engine.max_string_size > 0 && len > 0 && (len as usize) > engine.max_string_size {
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
len as usize,
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let ch = *args[2].downcast_ref::< char>().unwrap();
|
||||
let s = args[0].downcast_mut::<ImmutableString>().unwrap();
|
||||
|
||||
let copy = s.make_mut();
|
||||
for _ in 0..copy.chars().count() - len as usize {
|
||||
copy.push(ch);
|
||||
}
|
||||
|
||||
if engine.max_string_size > 0 && copy.len() > engine.max_string_size {
|
||||
Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
len as usize,
|
||||
copy.len(),
|
||||
Position::none(),
|
||||
)))
|
||||
} else {
|
||||
let ch = *args[2].downcast_ref::< char>().unwrap();
|
||||
let s = args[0].downcast_mut::<ImmutableString>().unwrap();
|
||||
|
||||
let copy = s.make_mut();
|
||||
for _ in 0..copy.chars().count() - len as usize {
|
||||
copy.push(ch);
|
||||
}
|
||||
|
||||
if engine.max_string_size > 0 && copy.len() > engine.max_string_size {
|
||||
Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
copy.len(),
|
||||
Position::none(),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user