ues saturating_sub to avoid panics

This commit is contained in:
Matthew Scheffel 2024-07-17 10:24:17 -03:00
parent f0ddd8e52c
commit 934650ce9a
No known key found for this signature in database
GPG key ID: 29D74EE3B1DA9FE3

View file

@ -119,7 +119,7 @@ impl PduEvent {
// deliberately allowing for the possibility of negative age // deliberately allowing for the possibility of negative age
let now: i128 = MilliSecondsSinceUnixEpoch::now().get().into(); let now: i128 = MilliSecondsSinceUnixEpoch::now().get().into();
let then: i128 = self.origin_server_ts.into(); let then: i128 = self.origin_server_ts.into();
let this_age: i128 = now - then; let this_age: i128 = now.saturating_sub(then);
unsigned.insert("age".to_owned(), to_raw_value(&this_age).unwrap()); unsigned.insert("age".to_owned(), to_raw_value(&this_age).unwrap());
self.unsigned = Some(to_raw_value(&unsigned).expect("unsigned is valid")); self.unsigned = Some(to_raw_value(&unsigned).expect("unsigned is valid"));