Skip to content

Commit

Permalink
struct Cdf*: Initialize with Default::default() instead of `mem::…
Browse files Browse the repository at this point in the history
…zeroed()`, as previously we were `mem::zeroed()`ing a `RwLock` (UB).
  • Loading branch information
kkysen committed Apr 23, 2024
1 parent be8c0e6 commit a5739a5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ use crate::src::tables::dav1d_partition_type_count;
use std::cmp;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::mem;
use std::sync::atomic::AtomicU32;
use std::sync::Arc;
use std::sync::RwLock;
use std::sync::RwLockWriteGuard;
use strum::EnumCount;

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub struct CdfContext {
pub m: CdfModeContext,
Expand All @@ -36,14 +35,14 @@ pub struct CdfContext {
pub dmv: CdfMvContext,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub struct CdfMvContext {
pub comp: [CdfMvComponent; 2],
pub joint: Align8<[u16; 4]>,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub struct CdfMvComponent {
pub classes: Align32<[u16; 16]>,
Expand All @@ -56,7 +55,7 @@ pub struct CdfMvComponent {
pub sign: Align4<[u16; 2]>,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub struct CdfCoefContext {
pub eob_bin_16: Align16<[[[u16; 8]; 2]; 2]>,
Expand All @@ -74,7 +73,7 @@ pub struct CdfCoefContext {
pub dc_sign: Align4<[[[u16; 2]; 3]; 2]>,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub struct CdfModeContext {
pub y_mode: Align32<[[u16; N_INTRA_PRED_MODES + 3]; 4]>,
Expand Down Expand Up @@ -5127,7 +5126,7 @@ pub unsafe fn rav1d_cdf_thread_alloc(
None
};
Ok(CdfThreadContext::Cdf(Arc::new(CdfThreadContext_data {
cdf: mem::zeroed(),
cdf: Default::default(),
progress,
})))
}

0 comments on commit a5739a5

Please sign in to comment.