File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ impl<const MAX_SIZE: usize> Encoder<MAX_SIZE> {
51
51
}
52
52
53
53
/// Encode an [`Arc`] as base 128 into the internal buffer.
54
+ #[ allow( clippy:: panic_in_result_fn) ]
54
55
pub ( crate ) const fn arc ( mut self , arc : Arc ) -> Result < Self > {
55
56
match self . state {
56
57
State :: Initial => {
@@ -61,15 +62,24 @@ impl<const MAX_SIZE: usize> Encoder<MAX_SIZE> {
61
62
self . state = State :: FirstArc ( arc) ;
62
63
Ok ( self )
63
64
}
64
- // Ensured not to overflow by `ARC_MAX_SECOND` check
65
- #[ allow( clippy:: arithmetic_side_effects) ]
66
65
State :: FirstArc ( first_arc) => {
67
66
if arc > ARC_MAX_SECOND {
68
67
return Err ( Error :: ArcInvalid { arc } ) ;
69
68
}
70
69
71
70
self . state = State :: Body ;
72
- self . bytes [ 0 ] = ( first_arc * ( ARC_MAX_SECOND + 1 ) ) as u8 + arc as u8 ;
71
+ self . bytes [ 0 ] = match ( ARC_MAX_SECOND + 1 ) . checked_mul ( first_arc) {
72
+ // TODO(tarcieri): use `and_then` when const traits are stable
73
+ Some ( n) => match n. checked_add ( arc) {
74
+ Some ( byte) => byte as u8 ,
75
+ None => {
76
+ // TODO(tarcieri): use `unreachable!`
77
+ panic ! ( "overflow prevented by ARC_MAX_SECOND check" )
78
+ }
79
+ } ,
80
+ // TODO(tarcieri): use `unreachable!`
81
+ None => panic ! ( "overflow prevented by ARC_MAX_SECOND check" ) ,
82
+ } ;
73
83
self . cursor = 1 ;
74
84
Ok ( self )
75
85
}
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ impl Parser {
59
59
None => 0 ,
60
60
} ;
61
61
62
+ // TODO(tarcieri): use `and_then` when const traits are stable
62
63
self . current_arc = match arc. checked_mul ( 10 ) {
63
64
Some ( arc) => match arc. checked_add ( digit as Arc ) {
64
65
None => return Err ( Error :: ArcTooBig ) ,
You can’t perform that action at this time.
0 commit comments