Skip to content

Commit 87d79a2

Browse files
authored
Merge pull request #232 from mozilla/checked-integer
Add a CheckedInteger type to ensure checked arithmetic
2 parents ae772de + 520f4a1 commit 87d79a2

File tree

5 files changed

+234
-132
lines changed

5 files changed

+234
-132
lines changed

mp4parse/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -975,16 +975,16 @@ pub struct TrackTimeScale<T: Num>(pub T, pub usize);
975975
/// A time to be scaled by the track's local (mdhd) timescale.
976976
/// Members are time in scale units and the track id.
977977
#[derive(Debug, Copy, Clone, PartialEq)]
978-
pub struct TrackScaledTime<T: Num>(pub T, pub usize);
978+
pub struct TrackScaledTime<T>(pub T, pub usize);
979979

980980
impl<T> std::ops::Add for TrackScaledTime<T>
981981
where
982-
T: Num,
982+
T: num_traits::CheckedAdd,
983983
{
984-
type Output = TrackScaledTime<T>;
984+
type Output = Option<Self>;
985985

986-
fn add(self, other: TrackScaledTime<T>) -> TrackScaledTime<T> {
987-
TrackScaledTime::<T>(self.0 + other.0, self.1)
986+
fn add(self, other: TrackScaledTime<T>) -> Self::Output {
987+
self.0.checked_add(&other.0).map(|sum| Self(sum, self.1))
988988
}
989989
}
990990

mp4parse_capi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
2626
byteorder = "1.2.1"
2727
log = "0.4"
2828
mp4parse = {version = "0.11.2", path = "../mp4parse"}
29-
num-traits = "0.2.0"
29+
num = "0.3.0"
3030

3131
[dev-dependencies]
3232
env_logger = "0.7.1"

mp4parse_capi/examples/dump.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ fn dump_file(filename: &str) {
6262
for i in 0..counts {
6363
let mut track_info = Mp4parseTrackInfo {
6464
track_type: Mp4parseTrackType::Audio,
65-
track_id: 0,
66-
duration: 0,
67-
media_time: 0,
65+
..Default::default()
6866
};
6967
match mp4parse_get_track_info(parser, i, &mut track_info) {
7068
Mp4parseStatus::Ok => {

0 commit comments

Comments
 (0)