11#![ allow( clippy:: useless_conversion) ]
22
3- use super :: mystd:: ffi:: { OsStr , OsString } ;
3+ use super :: mystd:: ffi:: OsStr ;
44use super :: mystd:: fs;
5- use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
5+ use super :: mystd:: os:: unix:: ffi:: OsStrExt ;
66use super :: mystd:: path:: { Path , PathBuf } ;
77use super :: Either ;
8- use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash , Vec } ;
8+ use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash } ;
9+ use alloc:: string:: String ;
910use alloc:: sync:: Arc ;
11+ use alloc:: vec:: Vec ;
1012use core:: convert:: { TryFrom , TryInto } ;
1113use core:: str;
1214#[ cfg( feature = "ruzstd" ) ]
@@ -393,7 +395,7 @@ fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> {
393395 Some ( ( ) )
394396}
395397
396- const DEBUG_PATH : & [ u8 ] = b "/usr/lib/debug";
398+ const DEBUG_PATH : & str = "/usr/lib/debug" ;
397399
398400fn debug_path_exists ( ) -> bool {
399401 cfg_if:: cfg_if! {
@@ -403,7 +405,7 @@ fn debug_path_exists() -> bool {
403405
404406 let mut exists = DEBUG_PATH_EXISTS . load( Ordering :: Relaxed ) ;
405407 if exists == 0 {
406- exists = if Path :: new( OsStr :: from_bytes ( DEBUG_PATH ) ) . is_dir( ) {
408+ exists = if Path :: new( DEBUG_PATH ) . is_dir( ) {
407409 1
408410 } else {
409411 2
@@ -422,8 +424,8 @@ fn debug_path_exists() -> bool {
422424/// The format of build id paths is documented at:
423425/// https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
424426fn locate_build_id ( build_id : & [ u8 ] ) -> Option < PathBuf > {
425- const BUILD_ID_PATH : & [ u8 ] = b "/usr/lib/debug/.build-id/";
426- const BUILD_ID_SUFFIX : & [ u8 ] = b ".debug";
427+ const BUILD_ID_PATH : & str = "/usr/lib/debug/.build-id/" ;
428+ const BUILD_ID_SUFFIX : & str = ".debug" ;
427429
428430 if build_id. len ( ) < 2 {
429431 return None ;
@@ -434,25 +436,17 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
434436 }
435437
436438 let mut path =
437- Vec :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
438- path. extend ( BUILD_ID_PATH ) ;
439- path. push ( hex ( build_id[ 0 ] >> 4 ) ) ;
440- path. push ( hex ( build_id[ 0 ] & 0xf ) ) ;
441- path. push ( b '/') ;
439+ String :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
440+ path. push_str ( BUILD_ID_PATH ) ;
441+ path. push ( char :: from_digit ( ( build_id[ 0 ] >> 4 ) as u32 , 16 ) ? ) ;
442+ path. push ( char :: from_digit ( ( build_id[ 0 ] & 0xf ) as u32 , 16 ) ? ) ;
443+ path. push ( '/' ) ;
442444 for byte in & build_id[ 1 ..] {
443- path. push ( hex ( byte >> 4 ) ) ;
444- path. push ( hex ( byte & 0xf ) ) ;
445- }
446- path. extend ( BUILD_ID_SUFFIX ) ;
447- Some ( PathBuf :: from ( OsString :: from_vec ( path) ) )
448- }
449-
450- fn hex ( byte : u8 ) -> u8 {
451- if byte < 10 {
452- b'0' + byte
453- } else {
454- b'a' + byte - 10
445+ path. push ( char:: from_digit ( ( byte >> 4 ) as u32 , 16 ) ?) ;
446+ path. push ( char:: from_digit ( ( byte & 0xf ) as u32 , 16 ) ?) ;
455447 }
448+ path. push_str ( BUILD_ID_SUFFIX ) ;
449+ Some ( PathBuf :: from ( path) )
456450}
457451
458452/// Locate a file specified in a `.gnu_debuglink` section.
@@ -469,9 +463,8 @@ fn hex(byte: u8) -> u8 {
469463fn locate_debuglink ( path : & Path , filename : & [ u8 ] ) -> Option < PathBuf > {
470464 let path = fs:: canonicalize ( path) . ok ( ) ?;
471465 let parent = path. parent ( ) ?;
472- let mut f = PathBuf :: from ( OsString :: with_capacity (
473- DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ,
474- ) ) ;
466+ let mut f =
467+ PathBuf :: with_capacity ( DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ) ;
475468 let filename = Path :: new ( OsStr :: from_bytes ( filename) ) ;
476469
477470 // Try "/parent/filename" if it differs from "path"
@@ -482,9 +475,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
482475 }
483476
484477 // Try "/parent/.debug/filename"
485- let mut s = OsString :: from ( f) ;
486- s. clear ( ) ;
487- f = PathBuf :: from ( s) ;
478+ f. clear ( ) ;
488479 f. push ( parent) ;
489480 f. push ( ".debug" ) ;
490481 f. push ( filename) ;
@@ -494,10 +485,8 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
494485
495486 if debug_path_exists ( ) {
496487 // Try "/usr/lib/debug/parent/filename"
497- let mut s = OsString :: from ( f) ;
498- s. clear ( ) ;
499- f = PathBuf :: from ( s) ;
500- f. push ( OsStr :: from_bytes ( DEBUG_PATH ) ) ;
488+ f. clear ( ) ;
489+ f. push ( DEBUG_PATH ) ;
501490 f. push ( parent. strip_prefix ( "/" ) . unwrap ( ) ) ;
502491 f. push ( filename) ;
503492 if f. is_file ( ) {
0 commit comments