Skip to content

Foundation: remove deprecated bzero #1942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ open class NSMutableData : NSData {

/// Replaces with zeroes the contents of the data object in a given range.
open func resetBytes(in range: NSRange) {
bzero(mutableBytes.advanced(by: range.location), range.length)
memset(mutableBytes.advanced(by: range.location), 0, range.length)
}

/// Replaces the entire contents of the data object with the contents of another data object.
Expand Down
9 changes: 1 addition & 8 deletions Foundation/NSSwiftRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ import CoreFoundation
import WinSDK
#endif

// shim required for bzero
#if os(Android) || os(Windows)
@_transparent func bzero(_ ptr: UnsafeMutableRawPointer, _ size: size_t) {
memset(ptr, 0, size)
}
#endif

#if !_runtime(_ObjC)
/// The Objective-C BOOL type.
///
Expand Down Expand Up @@ -144,7 +137,7 @@ internal func _CFSwiftIsEqual(_ cf1: AnyObject, cf2: AnyObject) -> Bool {
// Ivars in _NSCF* types must be zeroed via an unsafe accessor to avoid deinit of potentially unsafe memory to accces as an object/struct etc since it is stored via a foreign object graph
internal func _CFZeroUnsafeIvars<T>(_ arg: inout T) {
withUnsafeMutablePointer(to: &arg) { (ptr: UnsafeMutablePointer<T>) -> Void in
bzero(UnsafeMutableRawPointer(ptr), MemoryLayout<T>.size)
memset(UnsafeMutableRawPointer(ptr), 0, MemoryLayout<T>.size)
}
}

Expand Down