File tree 1 file changed +9
-1
lines changed
library/std/src/sys/windows
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ pub fn is_terminal(h: &impl AsHandle) -> bool {
90
90
unsafe fn handle_is_console ( handle : BorrowedHandle < ' _ > ) -> bool {
91
91
let handle = handle. as_raw_handle ( ) ;
92
92
93
+ // A null handle means the process has no console.
94
+ if handle. is_null ( ) {
95
+ return false ;
96
+ }
97
+
93
98
let mut out = 0 ;
94
99
if c:: GetConsoleMode ( handle, & mut out) != 0 {
95
100
// False positives aren't possible. If we got a console then we definitely have a console.
@@ -102,7 +107,10 @@ unsafe fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
102
107
// trust the negative.
103
108
for std_handle in [ c:: STD_INPUT_HANDLE , c:: STD_OUTPUT_HANDLE , c:: STD_ERROR_HANDLE ] {
104
109
let std_handle = c:: GetStdHandle ( std_handle) ;
105
- if std_handle != handle && c:: GetConsoleMode ( std_handle, & mut out) != 0 {
110
+ if !std_handle. is_null ( )
111
+ && std_handle != handle
112
+ && c:: GetConsoleMode ( std_handle, & mut out) != 0
113
+ {
106
114
return false ;
107
115
}
108
116
}
You can’t perform that action at this time.
0 commit comments