@@ -154,7 +154,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
154154
155155#[ cfg( not( target_os = "espidf" ) ) ]
156156pub fn getcwd ( ) -> io:: Result < PathBuf > {
157- let mut buf = Vec :: with_capacity ( 512 ) ;
157+ let mut buf = Vec :: try_with_capacity ( 512 ) . map_err ( |_| io :: ErrorKind :: OutOfMemory ) ? ;
158158 loop {
159159 unsafe {
160160 let ptr = buf. as_mut_ptr ( ) as * mut libc:: c_char ;
@@ -352,7 +352,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
352352 "KERN_PROC_PATHNAME sysctl returned zero-length string" ,
353353 ) ) ;
354354 }
355- let mut path: Vec < u8 > = Vec :: with_capacity ( path_len) ;
355+ let mut path: Vec < u8 > =
356+ Vec :: try_with_capacity ( path_len) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
356357 cvt ( libc:: sysctl (
357358 mib. as_ptr ( ) ,
358359 mib. len ( ) as libc:: c_uint ,
@@ -438,7 +439,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
438439 if sz == 0 {
439440 return Err ( io:: Error :: last_os_error ( ) ) ;
440441 }
441- let mut v: Vec < u8 > = Vec :: with_capacity ( sz as usize ) ;
442+ let mut v: Vec < u8 > =
443+ Vec :: try_with_capacity ( sz as usize ) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
442444 let err = libc:: _NSGetExecutablePath ( v. as_mut_ptr ( ) as * mut i8 , & mut sz) ;
443445 if err != 0 {
444446 return Err ( io:: Error :: last_os_error ( ) ) ;
@@ -726,7 +728,7 @@ pub fn home_dir() -> Option<PathBuf> {
726728 n if n < 0 => 512 as usize ,
727729 n => n as usize ,
728730 } ;
729- let mut buf = Vec :: with_capacity ( amt) ;
731+ let mut buf = Vec :: try_with_capacity ( amt) . ok ( ) ? ;
730732 let mut passwd: libc:: passwd = mem:: zeroed ( ) ;
731733 let mut result = ptr:: null_mut ( ) ;
732734 match libc:: getpwuid_r (
0 commit comments