Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Fix undefined wrapping behavior triggered by Rust nightly (fix #579) #582

Merged
merged 2 commits into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions core/src/avm1/value.rs
Expand Up @@ -623,10 +623,8 @@ pub fn f64_to_string(n: f64) -> String {
pub fn f64_to_wrapping_u16(n: f64) -> u16 {
if !n.is_finite() {
0
} else if n >= 0.0 {
(n % 65536.0) as u16
} else {
((n.trunc() % 65536.0) + 65536.0) as u16
n.trunc().rem_euclid(65536.0) as u16
}
}

Expand All @@ -642,10 +640,8 @@ pub fn f64_to_wrapping_i16(n: f64) -> i16 {
pub fn f64_to_wrapping_u32(n: f64) -> u32 {
if !n.is_finite() {
0
} else if n >= 0.0 {
(n % 4294967296.0) as u32
} else {
((n.trunc() % 4294967296.0) + 4294967296.0) as u32
n.trunc().rem_euclid(4294967296.0) as u32
}
}

Expand Down
2 changes: 1 addition & 1 deletion swf/src/write.rs
Expand Up @@ -303,7 +303,7 @@ impl<W: Write> Writer<W> {
}

fn write_fbits(&mut self, num_bits: u8, n: f32) -> Result<()> {
self.write_ubits(num_bits, (n * 65536f32) as u32)
self.write_sbits(num_bits, (n * 65536f32) as i32)
}

fn write_encoded_u32(&mut self, mut n: u32) -> Result<()> {
Expand Down