Skip to content

Commit 33f5603

Browse files
authored
Merge pull request #2302 from compnerd/CFString
2 parents 329d35b + 7988759 commit 33f5603

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CoreFoundation/URL.subproj/CFURLSessionInterface.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ static CFURLSessionMultiCode MakeMultiCode(CURLMcode value) {
3232
return (CFURLSessionMultiCode) { value };
3333
}
3434

35-
CFStringRef CFURLSessionCreateErrorDescription(int value) {
36-
const char *description = curl_easy_strerror(value);
37-
return CFStringCreateWithBytes(kCFAllocatorSystemDefault,
38-
(const uint8_t *)description, strlen(description), kCFStringEncodingUTF8, NO);
35+
const char *CFURLSessionEasyCodeDescription(CFURLSessionEasyCode code) {
36+
return curl_easy_strerror(code.value);
3937
}
4038

4139
CFURLSessionEasyHandle _Nonnull CFURLSessionEasyHandleInit() {

CoreFoundation/URL.subproj/CFURLSessionInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct CFURLSessionEasyCode {
5656
int value;
5757
} CFURLSessionEasyCode;
5858

59-
CF_EXPORT CFStringRef _Nonnull CFURLSessionCreateErrorDescription(int value);
59+
CF_EXPORT const char * _Nullable CFURLSessionEasyCodeDescription(CFURLSessionEasyCode code);
6060

6161
CF_EXPORT int const CFURLSessionEasyErrorSize;
6262

Foundation/URLSession/libcurl/MultiHandle.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ fileprivate extension URLSession._MultiHandle {
217217
// Find the NSURLError code
218218
var error: NSError?
219219
if let errorCode = easyHandle.urlErrorCode(for: easyCode) {
220-
let errorDescription = easyHandle.errorBuffer[0] != 0 ?
221-
String(cString: easyHandle.errorBuffer) :
222-
unsafeBitCast(CFURLSessionCreateErrorDescription(easyCode.value), to: NSString.self) as String
220+
var errorDescription: String = ""
221+
if easyHandle.errorBuffer[0] == 0 {
222+
let description = CFURLSessionEasyCodeDescription(easyCode)!
223+
errorDescription = NSString(bytes: UnsafeMutableRawPointer(mutating: description), length: strlen(description), encoding: String.Encoding.utf8.rawValue)! as String
224+
} else {
225+
errorDescription = String(cString: easyHandle.errorBuffer)
226+
}
227+
223228
error = NSError(domain: NSURLErrorDomain, code: errorCode, userInfo: [
224229
NSLocalizedDescriptionKey: errorDescription
225230
])

0 commit comments

Comments
 (0)