Skip to content

Commit b3cb43f

Browse files
committed
Ensure the string passed to PathIsRelativeW is null terminated
`CompilationDatabaseTests` have been flakey on Windows since #2334. This didn't really introduce the failure though - it just added tests that now catch it. The underlying cause is that `filename.isAbsolutePath` sometimes returns `true` for a relative path, which then causes the CWD to be prepended instead of the given `compileCommandsDirectory`. `PathIsRelativeW` requires a null terminated string, so presumably we were hitting junk after the initial path that sometimes turned it into an absolute path. From the Windows docs: > A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to search. Fixes #2360 Resolves rdar://165006835
1 parent b539999 commit b3cb43f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/BuildServerIntegration/CompilationDatabase.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ enum CompilationDatabaseDecodingError: Error {
206206
fileprivate extension String {
207207
var isAbsolutePath: Bool {
208208
#if os(Windows)
209-
Array(self.utf16).withUnsafeBufferPointer { buffer in
210-
return !PathIsRelativeW(buffer.baseAddress)
209+
// PathIsRelativeW requires a null-terminated UTF16 encoded string
210+
return withCString(encodedAs: UTF16.self) { ptr in
211+
return !PathIsRelativeW(ptr)
211212
}
212213
#else
213214
return self.hasPrefix("/")

0 commit comments

Comments
 (0)