[vlc-commits] securetransport: Use FromCFString on darwin

Marvin Scholz git at videolan.org
Sat Oct 20 20:06:09 CEST 2018


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon Oct  8 10:52:22 2018 +0200| [4ec08f43c40fb334f8cfd0f08403a05e299aae10] | committer: Marvin Scholz

securetransport: Use FromCFString on darwin

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4ec08f43c40fb334f8cfd0f08403a05e299aae10
---

 modules/misc/securetransport.c | 43 +++---------------------------------------
 1 file changed, 3 insertions(+), 40 deletions(-)

diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index 6928e9565d..68d91eeb81 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -35,6 +35,8 @@
 #include <Security/SecureTransport.h>
 #include <TargetConditionals.h>
 
+#include <vlc_charset.h>
+
 /* From MacErrors.h (cannot be included because it isn't present in iOS: */
 #ifndef ioErr
 # define ioErr -36
@@ -67,45 +69,6 @@ static CFMutableArrayRef alpnToCFArray(const char *const *alpn)
     return alpnValues;
 }
 
-/* Obtains a copy of the contents of a CFString in ASCII encoding.
- * Returns char* (must be freed by caller) or NULL on failure.
- */
-static char* CFStringCopyASCIICString(CFStringRef cfString)
-{
-    // Try the quick way to obtain the buffer
-    const char *tmpBuffer = CFStringGetCStringPtr(cfString, kCFStringEncodingASCII);
-
-    if (tmpBuffer != NULL) {
-       return strdup(tmpBuffer);
-    }
-
-    // The quick way did not work, try the long way
-    CFIndex length = CFStringGetLength(cfString);
-    CFIndex maxSize =
-        CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingASCII);
-
-    // If result would exceed LONG_MAX, kCFNotFound is returned
-    if (unlikely(maxSize == kCFNotFound)) {
-        return NULL;
-    }
-
-    // Account for the null terminator
-    maxSize++;
-
-    char *buffer = (char *)malloc(maxSize);
-
-    if (unlikely(buffer == NULL)) {
-        return NULL;
-    }
-
-    // Copy CFString in requested encoding to buffer
-    Boolean success = CFStringGetCString(cfString, buffer, maxSize, kCFStringEncodingASCII);
-
-    if (!success)
-        FREENULL(buffer);
-    return buffer;
-}
-
 /* Returns the first entry copy of the ALPN array as char*
  * or NULL on failure.
  */
@@ -117,7 +80,7 @@ static char* CFArrayALPNCopyFirst(CFArrayRef alpnArray)
         return NULL;
 
     CFStringRef alpnVal = CFArrayGetValueAtIndex(alpnArray, 0);
-    return CFStringCopyASCIICString(alpnVal);
+    return FromCFString(alpnVal, kCFStringEncodingASCII);
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list