From 41d559c4a9b8311ff18803ad795b211d80f04cc5 Mon Sep 17 00:00:00 2001 From: Akemi Date: Mon, 9 Apr 2018 16:10:48 +0200 Subject: [PATCH] cocoa-cb: fix a warning with swift 4.1 and slight cleanup the icc profile data is mutated to an UnsafeMutablePointer and could possibly changed. therefore the size of it should be accessed before a possible change. --- osdep/macOS_mpv_helper.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osdep/macOS_mpv_helper.swift b/osdep/macOS_mpv_helper.swift index 5d80e7b5b0..b023c4f098 100644 --- a/osdep/macOS_mpv_helper.swift +++ b/osdep/macOS_mpv_helper.swift @@ -127,9 +127,13 @@ class MPVHelper: NSObject { func setRenderICCProfile(_ profile: NSColorSpace) { if mpvRenderContext == nil { return } - var iccData = profile.iccProfileData - iccData!.withUnsafeMutableBytes { (u8Ptr: UnsafeMutablePointer) in - let iccBstr = bstrdup(nil, bstr(start: u8Ptr, len: iccData!.count)) + guard var iccData = profile.iccProfileData else { + sendWarning("Invalid ICC profile data.") + return + } + let iccSize = iccData.count + iccData.withUnsafeMutableBytes { (u8Ptr: UnsafeMutablePointer) in + let iccBstr = bstrdup(nil, bstr(start: u8Ptr, len: iccSize)) var icc = mpv_byte_array(data: iccBstr.start, size: iccBstr.len) let params = mpv_render_param(type: MPV_RENDER_PARAM_ICC_PROFILE, data: &icc) mpv_render_context_set_parameter(mpvRenderContext, params)