Skip to content

Commit cb2b1db

Browse files
author
HeroicKatora
authored
Merge pull request #218 from paolobarbolini/more-bounds
Remove even more bounds checks
2 parents 56bb2a0 + 530a309 commit cb2b1db

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &
2020
}
2121

2222
/// Arch-specific implementation of 8x8 IDCT.
23-
pub fn get_dequantize_and_idct_block_8x8() -> Option<unsafe fn(&[i16], &[u16; 64], usize, &mut [u8])>
23+
pub fn get_dequantize_and_idct_block_8x8() -> Option<unsafe fn(&[i16; 64], &[u16; 64], usize, &mut [u8])>
2424
{
2525
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
2626
#[allow(unsafe_code)]

src/arch/ssse3.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ unsafe fn transpose8(data: &mut [__m128i; 8]) {
122122
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
123123
#[target_feature(enable = "ssse3")]
124124
pub unsafe fn dequantize_and_idct_block_8x8(
125-
coefficients: &[i16],
125+
coefficients: &[i16; 64],
126126
quantization_table: &[u16; 64],
127127
output_linestride: usize,
128128
output: &mut [u8],
129129
) {
130-
assert!(coefficients.len() >= 64);
131130
// The loop below will write to positions [output_linestride * i, output_linestride * i + 8)
132131
// for 0<=i<8. Thus, the last accessed position is at an offset of output_linestrade * 7 + 7,
133132
// and if that position is in-bounds, so are all other accesses.

src/huffman.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ impl HuffmanTable {
213213
let bits_remaining = LUT_BITS - size;
214214
let start = (huffcode[i] << bits_remaining) as usize;
215215

216-
for j in 0 .. 1 << bits_remaining {
217-
lut[start + j] = (values[i], size);
216+
let val = (values[i], size);
217+
for b in &mut lut[start..][..1 << bits_remaining] {
218+
*b = val;
218219
}
219220
}
220221

src/idct.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,11 @@ fn dequantize_and_idct_block_4x4(
508508
let x0 = x0 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);
509509
let x2 = x2 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);
510510

511-
output[i * output_linestride + 0] = stbi_clamp((x0 + t2) >> FINAL_BITS);
512-
output[i * output_linestride + 3] = stbi_clamp((x0 - t2) >> FINAL_BITS);
513-
output[i * output_linestride + 1] = stbi_clamp((x2 + t0) >> FINAL_BITS);
514-
output[i * output_linestride + 2] = stbi_clamp((x2 - t0) >> FINAL_BITS);
511+
let output = &mut output[i * output_linestride..][..4];
512+
output[0] = stbi_clamp((x0 + t2) >> FINAL_BITS);
513+
output[3] = stbi_clamp((x0 - t2) >> FINAL_BITS);
514+
output[1] = stbi_clamp((x2 + t0) >> FINAL_BITS);
515+
output[2] = stbi_clamp((x2 - t0) >> FINAL_BITS);
515516
}
516517
}
517518

src/upsampler.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ impl Upsample for UpsamplerH1V2 {
181181
let input_near = &input[row_near as usize * row_stride ..];
182182
let input_far = &input[row_far as usize * row_stride ..];
183183

184-
for i in 0 .. output_width {
184+
let output = &mut output[..output_width];
185+
let input_near = &input_near[..output_width];
186+
let input_far = &input_far[..output_width];
187+
for i in 0..output_width {
185188
output[i] = ((3 * input_near[i] as u32 + input_far[i] as u32 + 2) >> 2) as u8;
186189
}
187190
}

0 commit comments

Comments
 (0)