Skip to content

Commit bfcec90

Browse files
authored
Merge pull request #2043 from xymus/safe-ioi-in-nle
Fix potential memory corruption in `CachedCompilation.Iterator`
2 parents 575c37c + 7e168ab commit bfcec90

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Sources/SwiftDriver/SwiftScan/SwiftScanCAS.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,18 @@ extension CachedCompilation: Sequence {
7878
public struct Iterator: IteratorProtocol {
7979
public typealias Element = CachedOutput
8080
let limit: UInt32
81-
let ptr: swiftscan_cached_compilation_t
82-
let lib: SwiftScan
81+
let sequence: CachedCompilation
8382
var idx: UInt32 = 0
8483
public mutating func next() -> CachedOutput? {
8584
guard idx < self.limit else { return nil }
86-
let output = self.lib.api.swiftscan_cached_compilation_get_output(self.ptr, idx)
85+
let output = self.sequence.lib.api.swiftscan_cached_compilation_get_output(self.sequence.ptr, idx)
8786
idx += 1
8887
// output can never be nil.
89-
return CachedOutput(output!, lib: self.lib)
88+
return CachedOutput(output!, lib: self.sequence.lib)
9089
}
9190
}
9291
public func makeIterator() -> Iterator {
93-
return Iterator(limit: self.count, ptr: self.ptr, lib: self.lib)
92+
return Iterator(limit: self.count, sequence: self)
9493
}
9594
}
9695

0 commit comments

Comments
 (0)