@@ -48,14 +48,10 @@ impl FileDescription for Event {
48
48
bytes : & mut [ u8 ] ,
49
49
ecx : & mut MiriInterpCx < ' tcx > ,
50
50
) -> InterpResult < ' tcx , io:: Result < usize > > {
51
- // Use bytes[0..8] so it won't fail when bytes's size > 8.
52
- let mut buffer = match bytes[ 0 ..8 ] . try_into ( ) {
53
- Ok ( bytes) => bytes,
54
- Err ( _) => {
55
- // Size of bytes is less than 8.
56
- return Ok ( Err ( Error :: from ( ErrorKind :: InvalidInput ) ) ) ;
57
- }
58
- } ;
51
+ // Check the size of slice, and return error only if the size of the slice < 8.
52
+ if <[ u8 ; 8 ] >:: try_from ( & bytes[ 0 ..8 ] ) . is_err ( ) {
53
+ return Ok ( Err ( Error :: from ( ErrorKind :: InvalidInput ) ) ) ;
54
+ }
59
55
if self . counter == 0 {
60
56
if self . is_nonblock {
61
57
return Ok ( Err ( Error :: from ( ErrorKind :: WouldBlock ) ) ) ;
@@ -65,13 +61,12 @@ impl FileDescription for Event {
65
61
}
66
62
} else {
67
63
// Return the counter in the host endianness using the buffer provided by caller.
68
- //TODO: check if why mutable bytes is not used? is this not the same buffer?
69
- buffer = match ecx. tcx . sess . target . endian {
64
+ let counter_byte: [ u8 ; 8 ] = match ecx. tcx . sess . target . endian {
70
65
Endian :: Little => self . counter . to_le_bytes ( ) ,
71
66
Endian :: Big => self . counter . to_be_bytes ( ) ,
72
67
} ;
68
+ bytes. copy_from_slice ( & counter_byte) ;
73
69
self . counter = 0 ;
74
- // It is always 8 bytes being read.
75
70
return Ok ( Ok ( 8 ) ) ;
76
71
}
77
72
}
@@ -94,7 +89,7 @@ impl FileDescription for Event {
94
89
bytes : & [ u8 ] ,
95
90
ecx : & mut MiriInterpCx < ' tcx > ,
96
91
) -> InterpResult < ' tcx , io:: Result < usize > > {
97
- let mut bytes = match bytes[ 0 ..8 ] . try_into ( ) {
92
+ let bytes = match bytes[ 0 ..8 ] . try_into ( ) {
98
93
Ok ( bytes) => bytes,
99
94
Err ( _) => {
100
95
// Size of bytes is less than 8.
@@ -121,7 +116,7 @@ impl FileDescription for Event {
121
116
throw_unsup_format ! ( "eventfd: blocking is unsupported" ) ;
122
117
}
123
118
} else {
124
- self . counter . checked_add ( num) . unwrap ( ) ;
119
+ self . counter = self . counter . checked_add ( num) . unwrap ( ) ;
125
120
}
126
121
Ok ( Ok ( 8 ) )
127
122
}
0 commit comments