mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-07 12:13:19 +00:00
Merge pull request #5894 from jayzed80/fix/eps-bitshift-min
fix(eps): bitshift by the most negative integer no longer overflows on negation
This commit is contained in:
@@ -816,7 +816,7 @@ impl<'a> Interp<'a> {
|
||||
},
|
||||
Bitshift => {
|
||||
let (s, v) = (self.pop_int()?, self.pop_int()?);
|
||||
let r = if s >= 0 { v.checked_shl(s.min(63) as u32) } else { v.checked_shr((-s).min(63) as u32) };
|
||||
let r = if s >= 0 { v.checked_shl(s.min(63) as u32) } else { v.checked_shr(s.saturating_neg().min(63) as u32) };
|
||||
self.push(Obj::Int(r.unwrap_or(0)))?;
|
||||
}
|
||||
True => self.push(Obj::Bool(true))?,
|
||||
|
||||
@@ -1400,3 +1400,10 @@ fn stored_graphics_states_use_up_the_memory_budget() {
|
||||
assert!(r.warnings.iter().any(|w| w.contains("uses too much memory")), "{body}: {:?}", r.warnings);
|
||||
}
|
||||
}
|
||||
|
||||
/// `bitshift` by the most negative integer shifts right by everything, not a negation overflow.
|
||||
#[test]
|
||||
fn bitshift_by_the_most_negative_integer_does_not_panic() {
|
||||
let r = read("0 0 10 10 rectfill 1 -9223372036854775808 bitshift pop -1 -9223372036854775808 bitshift pop");
|
||||
assert_eq!(objects(&r.document).len(), 1, "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user