Skip to content

Commit 017c533

Browse files
committed
Fix warning: overlapping access to 'self'
> Overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable
1 parent bafd8c2 commit 017c533

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Foundation/NSCalendar.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,9 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
583583
var at: CFAbsoluteTime = date.timeIntervalSinceReferenceDate
584584

585585
let res: Bool = withUnsafeMutablePointer(to: &at) { t in
586+
let copy = vector
586587
return vector.withUnsafeMutableBufferPointer { (vectorBuffer: inout UnsafeMutableBufferPointer<Int32>) in
587-
return _CFCalendarAddComponentsV(_cfObject, t, CFOptionFlags(opts.rawValue), compDesc, vectorBuffer.baseAddress!, Int32(vector.count))
588+
return _CFCalendarAddComponentsV(_cfObject, t, CFOptionFlags(opts.rawValue), compDesc, vectorBuffer.baseAddress!, Int32(copy.count))
588589
}
589590
}
590591

@@ -603,8 +604,9 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
603604
return intArrayBuffer.baseAddress!.advanced(by: idx)
604605
}
605606

607+
let copy = vector
606608
return vector.withUnsafeMutableBufferPointer { (vecBuffer: inout UnsafeMutableBufferPointer<UnsafeMutablePointer<Int32>>) in
607-
return _CFCalendarGetComponentDifferenceV(_cfObject, startingDate.timeIntervalSinceReferenceDate, resultDate.timeIntervalSinceReferenceDate, CFOptionFlags(opts.rawValue), compDesc, vecBuffer.baseAddress!, Int32(vector.count))
609+
return _CFCalendarGetComponentDifferenceV(_cfObject, startingDate.timeIntervalSinceReferenceDate, resultDate.timeIntervalSinceReferenceDate, CFOptionFlags(opts.rawValue), compDesc, vecBuffer.baseAddress!, Int32(copy.count))
608610
}
609611
}
610612
if res {

TestFoundation/TestNSData.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,14 @@ extension TestNSData {
924924
XCTAssertEqual(mutatingHello.count, helloLength * 2, "The length should have changed")
925925

926926
// Get the underlying data for hello2
927+
let copy = mutatingHello
927928
mutatingHello.withUnsafeMutableBytes { (bytes : UnsafeMutablePointer<UInt8>) in
928929
XCTAssertEqual(bytes.pointee, 0x68, "First byte should be 0x68")
929930

930931
// Mutate it
931932
bytes.pointee = 0x67
932933
XCTAssertEqual(bytes.pointee, 0x67, "First byte should be 0x67")
933-
XCTAssertEqual(mutatingHello[0], 0x67, "First byte accessed via other method should still be 0x67")
934+
XCTAssertEqual(copy[0], 0x67, "First byte accessed via other method should still be 0x67")
934935

935936
// Verify that the first data is still correct
936937
XCTAssertEqual(hello[0], 0x68, "The first byte should still be 0x68")

0 commit comments

Comments
 (0)