File tree Expand file tree Collapse file tree 5 files changed +13
-11
lines changed Expand file tree Collapse file tree 5 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ impl From<ErrorKind> for Error {
4040
4141impl From < Context < ErrorKind > > for Error {
4242 fn from ( inner : Context < ErrorKind > ) -> Error {
43- Error { inner : inner }
43+ Error { inner }
4444 }
4545}
4646
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ fn cmd_status(_: &clap::ArgMatches) -> Result<()> {
6060 } else {
6161 Err ( failure:: err_msg ( "No surface control device not found" ) )
6262 . context ( ErrorKind :: DeviceAccess )
63- . map_err ( |e| e . into ( ) )
63+ . map_err ( Into :: into)
6464 }
6565}
6666
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ impl PowerState {
2020 }
2121 }
2222
23- pub fn as_str ( & self ) -> & ' static str {
23+ pub fn as_str ( self ) -> & ' static str {
2424 match self {
2525 PowerState :: Off => "off" ,
2626 PowerState :: On => "on" ,
@@ -62,7 +62,7 @@ impl Device {
6262 } else {
6363 Err ( failure:: err_msg ( "Surface dGPU hot-plug device not found" ) )
6464 . context ( ErrorKind :: DeviceAccess )
65- . map_err ( |e| e . into ( ) )
65+ . map_err ( Into :: into)
6666 }
6767 }
6868
@@ -76,8 +76,9 @@ impl Device {
7676
7777 let mut buf = [ 0 ; 4 ] ;
7878 let len = file. read ( & mut buf) . context ( ErrorKind :: Io ) ?;
79+ let len = std:: cmp:: min ( len + 1 , buf. len ( ) ) ;
7980
80- let state = CStr :: from_bytes_with_nul ( & buf[ 0 ..len+ 1 ] )
81+ let state = CStr :: from_bytes_with_nul ( & buf[ 0 ..len] )
8182 . context ( ErrorKind :: InvalidData ) ?
8283 . to_str ( ) . context ( ErrorKind :: InvalidData ) ?
8384 . trim ( ) ;
Original file line number Diff line number Diff line change @@ -54,11 +54,11 @@ impl Device {
5454 Err ( ref e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => {
5555 Err ( failure:: err_msg ( "Surface latch device not found" ) )
5656 . context ( ErrorKind :: DeviceAccess )
57- . map_err ( |e| e . into ( ) )
57+ . map_err ( Into :: into)
5858 } ,
5959 Err ( e) => {
6060 Err ( e) . context ( ErrorKind :: DeviceAccess )
61- . map_err ( |e| e . into ( ) )
61+ . map_err ( Into :: into)
6262 } ,
6363 }
6464
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ impl Mode {
2626 }
2727 }
2828
29- pub fn short_str ( & self ) -> & ' static str {
29+ pub fn short_str ( self ) -> & ' static str {
3030 match self {
3131 Mode :: Normal => "1" ,
3232 Mode :: Battery => "2" ,
@@ -35,7 +35,7 @@ impl Mode {
3535 }
3636 }
3737
38- pub fn long_str ( & self ) -> & ' static str {
38+ pub fn long_str ( self ) -> & ' static str {
3939 match self {
4040 Mode :: Normal => "Normal" ,
4141 Mode :: Battery => "Battery-Saver" ,
@@ -79,7 +79,7 @@ impl Device {
7979 } else {
8080 Err ( failure:: err_msg ( "Surface performance-mode device not found" ) )
8181 . context ( ErrorKind :: DeviceAccess )
82- . map_err ( |e| e . into ( ) )
82+ . map_err ( Into :: into)
8383 }
8484 }
8585
@@ -93,8 +93,9 @@ impl Device {
9393
9494 let mut buf = [ 0 ; 4 ] ;
9595 let len = file. read ( & mut buf) . context ( ErrorKind :: Io ) ?;
96+ let len = std:: cmp:: min ( len + 1 , buf. len ( ) ) ;
9697
97- let state = CStr :: from_bytes_with_nul ( & buf[ 0 ..len+ 1 ] )
98+ let state = CStr :: from_bytes_with_nul ( & buf[ 0 ..len] )
9899 . context ( ErrorKind :: InvalidData ) ?
99100 . to_str ( ) . context ( ErrorKind :: InvalidData ) ?
100101 . trim ( ) ;
You can’t perform that action at this time.
0 commit comments