Remove implicit bounds checking from rcc module
This commit is contained in:
parent
cbc67469d3
commit
73d937dc33
@ -138,11 +138,17 @@ impl RccInfo {
|
|||||||
pub(crate) fn enable_and_reset_with_cs(&self, _cs: CriticalSection) {
|
pub(crate) fn enable_and_reset_with_cs(&self, _cs: CriticalSection) {
|
||||||
if self.refcount_idx_or_0xff != 0xff {
|
if self.refcount_idx_or_0xff != 0xff {
|
||||||
let refcount_idx = self.refcount_idx_or_0xff as usize;
|
let refcount_idx = self.refcount_idx_or_0xff as usize;
|
||||||
unsafe {
|
|
||||||
crate::_generated::REFCOUNTS[refcount_idx] += 1;
|
// Use .get_mut instead of []-operator so that we control how bounds checks happen.
|
||||||
}
|
// Otherwise, core::fmt will be pulled in here in order to format the integer in the
|
||||||
if unsafe { crate::_generated::REFCOUNTS[refcount_idx] } > 1 {
|
// out-of-bounds error.
|
||||||
return;
|
if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS }.get_mut(refcount_idx) {
|
||||||
|
*refcount += 1;
|
||||||
|
if *refcount > 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("refcount_idx out of bounds: {}", refcount_idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,11 +202,15 @@ impl RccInfo {
|
|||||||
pub(crate) fn disable_with_cs(&self, _cs: CriticalSection) {
|
pub(crate) fn disable_with_cs(&self, _cs: CriticalSection) {
|
||||||
if self.refcount_idx_or_0xff != 0xff {
|
if self.refcount_idx_or_0xff != 0xff {
|
||||||
let refcount_idx = self.refcount_idx_or_0xff as usize;
|
let refcount_idx = self.refcount_idx_or_0xff as usize;
|
||||||
unsafe {
|
|
||||||
crate::_generated::REFCOUNTS[refcount_idx] -= 1;
|
// Use .get_mut instead of []-operator so that we control how bounds checks happen.
|
||||||
}
|
// Otherwise, core::fmt will be pulled in here in order to format the integer in the
|
||||||
if unsafe { crate::_generated::REFCOUNTS[refcount_idx] } > 0 {
|
// out-of-bounds error.
|
||||||
return;
|
if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS }.get_mut(refcount_idx) {
|
||||||
|
*refcount -= 1;
|
||||||
|
if *refcount > 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user