fix arithmetic side-effects
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
52a561ff9e
commit
7397064edd
25 changed files with 139 additions and 114 deletions
|
@ -26,7 +26,7 @@ impl fmt::Display for Escape<'_> {
|
|||
fmt.write_str(s)?;
|
||||
// NOTE: we only expect single byte characters here - which is fine as long as
|
||||
// we only match single byte characters
|
||||
last = i + 1;
|
||||
last = i.saturating_add(1);
|
||||
}
|
||||
|
||||
if last < s.len() {
|
||||
|
|
|
@ -16,7 +16,15 @@ macro_rules! checked {
|
|||
#[cfg(not(debug_assertions))]
|
||||
#[macro_export]
|
||||
macro_rules! validated {
|
||||
($($input:tt)*) => { Ok($($input)*) }
|
||||
($($input:tt)*) => {
|
||||
//#[allow(clippy::arithmetic_side_effects)] {
|
||||
//Some($($input)*)
|
||||
// .ok_or_else(|| $crate::Error::Arithmetic("this error should never been seen"))
|
||||
//}
|
||||
|
||||
//NOTE: remove me when stmt_expr_attributes is stable
|
||||
$crate::checked!($($input)*)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
|
@ -15,7 +15,11 @@ pub fn string(length: usize) -> String {
|
|||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn timepoint_secs(range: Range<u64>) -> SystemTime { SystemTime::now() + secs(range) }
|
||||
pub fn timepoint_secs(range: Range<u64>) -> SystemTime {
|
||||
SystemTime::now()
|
||||
.checked_add(secs(range))
|
||||
.expect("range does not overflow SystemTime")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn secs(range: Range<u64>) -> Duration {
|
||||
|
|
|
@ -65,7 +65,7 @@ fn common_prefix_none() {
|
|||
|
||||
#[test]
|
||||
fn checked_add() {
|
||||
use utils::math::checked;
|
||||
use crate::checked;
|
||||
|
||||
let a = 1234;
|
||||
let res = checked!(a + 1).unwrap();
|
||||
|
@ -75,9 +75,9 @@ fn checked_add() {
|
|||
#[test]
|
||||
#[should_panic(expected = "overflow")]
|
||||
fn checked_add_overflow() {
|
||||
use utils::math::checked;
|
||||
use crate::checked;
|
||||
|
||||
let a: u64 = u64::MAX;
|
||||
let a = u64::MAX;
|
||||
let res = checked!(a + 1).expect("overflow");
|
||||
assert_eq!(res, 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue