@@ -154,7 +154,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
154
154
155
155
#[ cfg( not( target_os = "espidf" ) ) ]
156
156
pub 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 ) ? ;
158
158
loop {
159
159
unsafe {
160
160
let ptr = buf. as_mut_ptr ( ) as * mut libc:: c_char ;
@@ -352,7 +352,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
352
352
"KERN_PROC_PATHNAME sysctl returned zero-length string" ,
353
353
) ) ;
354
354
}
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 ) ?;
356
357
cvt ( libc:: sysctl (
357
358
mib. as_ptr ( ) ,
358
359
mib. len ( ) as libc:: c_uint ,
@@ -438,7 +439,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
438
439
if sz == 0 {
439
440
return Err ( io:: Error :: last_os_error ( ) ) ;
440
441
}
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 ) ?;
442
444
let err = libc:: _NSGetExecutablePath ( v. as_mut_ptr ( ) as * mut i8 , & mut sz) ;
443
445
if err != 0 {
444
446
return Err ( io:: Error :: last_os_error ( ) ) ;
@@ -726,7 +728,7 @@ pub fn home_dir() -> Option<PathBuf> {
726
728
n if n < 0 => 512 as usize ,
727
729
n => n as usize ,
728
730
} ;
729
- let mut buf = Vec :: with_capacity ( amt) ;
731
+ let mut buf = Vec :: try_with_capacity ( amt) . ok ( ) ? ;
730
732
let mut passwd: libc:: passwd = mem:: zeroed ( ) ;
731
733
let mut result = ptr:: null_mut ( ) ;
732
734
match libc:: getpwuid_r (
0 commit comments