@@ -351,35 +351,30 @@ public final class Process {
351351 pathString: ProcessEnv . path,
352352 currentWorkingDirectory: cwdOpt
353353 )
354+ var searchPaths : [ AbsolutePath ] = [ ]
354355#if os(Windows)
355- var searchPaths = Array < AbsolutePath > ( )
356356 var buffer = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
357-
358357 // The 32-bit Windows system directory
359- GetSystemDirectoryW ( & buffer, . init ( MAX_PATH + 1 ) )
360- searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
361-
358+ if GetSystemDirectoryW ( & buffer, buffer . count ) > 0 {
359+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
360+ }
362361 // The 16-bit Windows system directory
363362 if let systemDrive = ProcessEnv . vars [ " systemdrive " ] ,
364363 let systemPath = try ? AbsolutePath ( validating: " \( systemDrive) ) \\ System " ) {
365364 searchPaths. append ( systemPath)
366365 }
367-
368366 // The Windows directory
369- GetWindowsDirectoryW ( & buffer, . init( MAX_PATH + 1 ) )
370- searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
371-
372- searchPaths. append ( contentsOf: envSearchPaths)
373- #else
374- let searchPaths = envSearchPaths
367+ if GetWindowsDirectoryW ( & buffer, buffer. count) > 0 {
368+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
369+ }
375370#endif
371+ searchPaths. append ( contentsOf: envSearchPaths)
376372 // Lookup and cache the executable path.
377373 let value = lookupExecutablePath (
378374 filename: program,
379375 currentWorkingDirectory: cwdOpt,
380376 searchPaths: searchPaths
381377 )
382- Process . validatedExecutablesMap [ program] = value
383378 return value
384379 }
385380 // This should cover the most common cases, i.e. when the cache is most helpful.
0 commit comments