Skip to content

Commit a84a3ba

Browse files
committed
fix: (hopefully) overflows in silk_sum_sqr_shift_inner
1 parent 2fd8786 commit a84a3ba

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/silk/sum_sqr_shift.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
use crate::silk::macros::silk_CLZ32;
1+
use crate::silk::macros::{silk_CLZ32, silk_SMULBB};
22
use crate::silk::SigProc_FIX::silk_max_32;
33

44
fn silk_sum_sqr_shift_inner(mut nrg: i32, shft: i32, x: &[i16]) -> i32 {
55
let len = x.len();
66

77
let mut i = 0;
88
while i < len - 1 {
9-
let nrg_tmp = x[i] as i32 * x[i] as i32;
10-
let nrg_tmp = nrg_tmp.wrapping_add(x[i + 1] as i32 * x[i + 1] as i32);
11-
nrg = nrg.wrapping_add(nrg_tmp >> shft);
9+
let nrg_tmp = silk_SMULBB(x[i] as i32, x[i] as i32) as u32;
10+
let nrg_tmp = nrg_tmp.wrapping_add(silk_SMULBB(x[i + 1] as i32, x[i + 1] as i32) as u32);
11+
nrg = nrg.wrapping_add((nrg_tmp >> shft) as i32);
1212
i += 2;
1313
}
1414
if i < len {
1515
/* One sample left to process */
16-
let nrg_tmp = x[i] as i32 * x[i] as i32;
17-
nrg = nrg.wrapping_add(nrg_tmp >> shft);
16+
let nrg_tmp = silk_SMULBB(x[i] as i32, x[i] as i32) as u32;
17+
nrg = nrg.wrapping_add((nrg_tmp >> shft) as i32);
1818
}
1919

2020
debug_assert!(nrg >= 0);

0 commit comments

Comments
 (0)