Re-enable -Wcast-qual in WebCore for Apple ports
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Jan 2018 03:19:57 +0000 (03:19 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Jan 2018 03:19:57 +0000 (03:19 +0000)
<https://webkit.org/b/177895>
<rdar://problem/34960830>

Reviewed by Joseph Pecoraro.

Source/WebCore:

* Configurations/Base.xcconfig:
(WARNING_CFLAGS): Remove FIXME and add -Wcast-qual back to
arguments.

* crypto/mac/SerializedCryptoKeyWrapMac.mm:
(WebCore::createAndStoreMasterKey):
- Use checked_cf_cast<SecACLRef>().

* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange):
- Manually cast CFTypeRef to DDResultRef until
  DDResultGetTypeID() is available as SPI.

* platform/gamepad/mac/HIDGamepad.cpp:
(WebCore::HIDGamepad::initElementsFromArray):
- Use checked_cf_cast<IOHIDElementRef>().

* platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
(WebCore::MediaSampleAVFObjC::createImageSample):
(WebCore::CMSampleBufferIsRandomAccess):
(WebCore::CMSampleBufferIsNonDisplaying):
(WebCore::MediaSampleAVFObjC::createNonDisplayingCopy const):
- Use checked_cf_cast<CFMutableDictionaryRef>() and
  checked_cf_cast<CFDictionaryRef>().

* platform/graphics/cocoa/IOSurface.h:
(WebCore::IOSurface::asLayerContents):
- Use reinterpret_cast<id>() to cast from IOSurfaceRef to id.

* platform/graphics/cocoa/WebCoreDecompressionSession.mm:
(WebCore::WebCoreDecompressionSession::getFirstVideoFrame):
(WebCore::WebCoreDecompressionSession::automaticDequeue):
(WebCore::WebCoreDecompressionSession::imageForTime):
(WebCore::WebCoreDecompressionSession::getDecodeTime):
(WebCore::WebCoreDecompressionSession::getPresentationTime):
(WebCore::WebCoreDecompressionSession::getDuration):
- Use checked_cf_cast<CMSampleBufferRef>().

* platform/graphics/Font.h:
(WebCore::Font::m_kernedCFStringAttributes):
(WebCore::Font::m_nonKernedCFStringAttributes):
- Change type from RetainPtr<CFDictionaryRef> to
  RetainPtr<CFMutableDictionaryRef> since that's what they are.
* platform/graphics/mac/SimpleFontDataCoreText.cpp:
(WebCore::Font::getCFStringAttributes const):
- Replace local `mutableAttributes` variable with
  `attributesDictionary.get()` since it returns the correct type
  now.

* platform/ios/wak/WAKView.mm:
(-[WAKView _initWithViewRef:]):
(_WAKCopyWrapper):
* platform/ios/wak/WKView.mm:
(_WKViewClearSuperview):
(WKViewFirstChild):
(WKViewNextSibling):
- Use static_cast<WKViewRef>(const_cast<void*>()) to convert
  const void* variable to WKViewRef.

* platform/mac/PasteboardMac.mm:
(WebCore::flipImageSpec):
(WebCore::setDragImageImpl):
- Use const_cast<> to remove 'const' modifier from
  unsigned char pointers.  This regressed while -Wcast-qual was
  disabled for WebCore.

* platform/mac/SSLKeyGeneratorMac.mm:
(WebCore::signedPublicKeyAndChallengeString):
- Use checked_cf_cast<SecACLRef>().

* platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp:
(WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):
- Use checked_cf_cast<CFMutableDictionaryRef>().

* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::copyCONNECTProxyResponse):
- Use checked_cf_cast<CFHTTPMessageRef>().

* platform/network/cocoa/ResourceResponseCocoa.mm:
(WebCore::ResourceResponse::platformCertificateInfo const):
- Use checked_cf_cast<SecTrustRef>().

* platform/network/mac/CertificateInfoMac.mm:
(WebCore::CertificateInfo::containsNonRootSHA1SignedCertificate const):
(WebCore::CertificateInfo::dump const):
- Use checked_cf_cast<SecCertificateRef>().

* testing/cocoa/WebArchiveDumpSupport.mm:
(WebCoreTestSupport::createCFURLResponseFromResponseData):
- Use checked_cf_cast<>() for CFMutable* types.

Source/WTF:

* wtf/RetainPtr.h:
(WTF::RetainPtr::fromStorageTypeHelper const): Add const_cast<>
operator here since some CFTypes are not defined as const
pointers, which triggers a warning in C++ source with
-Wcast-qual when casting from CFTypeRef back to the original
type.  Note that we use const_cast<CF_BRIDGED_TYPE(id) void*>()
here (and in TypeCastsCF.h below) since this is what CFTypeRef
is defined as in CFBase.h, but without the 'const' modifier.
(WTF::RetainPtr::fromStorageType const): Ditto.

* wtf/cf/TypeCastsCF.h: Use #pragma once.
(WTF_DECLARE_CF_TYPE_TRAIT): Rename from DECLARE_CF_TYPE_TRAIT.
Don't #undef it so that it can be used in other source files.
(WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT): Add new macro that is used
for declaring CFMutable types.  The CFTypeID for CF_Foo_ and
CFMutable_Foo_ are the same, so we have to use a different macro
to declare type traits for those types.
(WTF::dynamic_cf_cast): Add assertion to catch issues in Debug
builds.
(WTF::checked_cf_cast): Inline code from WTF::dynamic_cf_cast
and change behavior to be more consistent between Debug and
Release builds, as well as other "checked" functions.
Previously this function would return nullptr in Release builds
if nullptr or the wrong type of object was passed in, but crash
in both cases on Debug builds.  The new behavior always returns
nullptr if nullptr was passed in (but never crashes), and always
crashes if the wrong type of object is passed in.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226483 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/RetainPtr.h
Source/WTF/wtf/cf/TypeCastsCF.h
Source/WebCore/ChangeLog
Source/WebCore/Configurations/Base.xcconfig
Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm
Source/WebCore/editing/cocoa/DataDetection.mm
Source/WebCore/platform/gamepad/mac/HIDGamepad.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm
Source/WebCore/platform/graphics/cocoa/IOSurface.h
Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm
Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp
Source/WebCore/platform/ios/wak/WAKView.mm
Source/WebCore/platform/ios/wak/WKView.mm
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp
Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp
Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm
Source/WebCore/platform/network/mac/CertificateInfoMac.mm
Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm

index dca55ca..ce5989c 100644 (file)
@@ -1,3 +1,39 @@
+2018-01-05  David Kilzer  <ddkilzer@apple.com>
+
+        Re-enable -Wcast-qual in WebCore for Apple ports
+        <https://webkit.org/b/177895>
+        <rdar://problem/34960830>
+
+        Reviewed by Joseph Pecoraro.
+
+        * wtf/RetainPtr.h:
+        (WTF::RetainPtr::fromStorageTypeHelper const): Add const_cast<>
+        operator here since some CFTypes are not defined as const
+        pointers, which triggers a warning in C++ source with
+        -Wcast-qual when casting from CFTypeRef back to the original
+        type.  Note that we use const_cast<CF_BRIDGED_TYPE(id) void*>()
+        here (and in TypeCastsCF.h below) since this is what CFTypeRef
+        is defined as in CFBase.h, but without the 'const' modifier.
+        (WTF::RetainPtr::fromStorageType const): Ditto.
+
+        * wtf/cf/TypeCastsCF.h: Use #pragma once.
+        (WTF_DECLARE_CF_TYPE_TRAIT): Rename from DECLARE_CF_TYPE_TRAIT.
+        Don't #undef it so that it can be used in other source files.
+        (WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT): Add new macro that is used
+        for declaring CFMutable types.  The CFTypeID for CF_Foo_ and
+        CFMutable_Foo_ are the same, so we have to use a different macro
+        to declare type traits for those types.
+        (WTF::dynamic_cf_cast): Add assertion to catch issues in Debug
+        builds.
+        (WTF::checked_cf_cast): Inline code from WTF::dynamic_cf_cast
+        and change behavior to be more consistent between Debug and
+        Release builds, as well as other "checked" functions.
+        Previously this function would return nullptr in Release builds
+        if nullptr or the wrong type of object was passed in, but crash
+        in both cases on Debug builds.  The new behavior always returns
+        nullptr if nullptr was passed in (but never crashes), and always
+        crashes if the wrong type of object is passed in.
+
 2018-01-04  Keith Miller  <keith_miller@apple.com>
 
         TypedArrays and Wasm should use index masking.
index 06464f4..545ec39 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2005, 2006, 2007, 2008, 2010, 2013, 2014 Apple Inc. All rights reserved.
+ *  Copyright (C) 2005-2018 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
 #import <Foundation/Foundation.h>
 #endif
 
+#ifndef CF_BRIDGED_TYPE
+#define CF_BRIDGED_TYPE(T)
+#endif
+
 #ifndef CF_RELEASES_ARGUMENT
 #define CF_RELEASES_ARGUMENT
 #endif
@@ -116,14 +120,14 @@ private:
     typename std::enable_if<std::is_convertible<U, id>::value, PtrType>::type
     fromStorageTypeHelper(StorageType ptr) const
     {
-        return (__bridge PtrType)ptr;
+        return (__bridge PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
 
     template<typename U>
     typename std::enable_if<!std::is_convertible<U, id>::value, PtrType>::type
     fromStorageTypeHelper(StorageType ptr) const
     {
-        return (PtrType)ptr;
+        return (PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
 
     PtrType fromStorageType(StorageType ptr) const { return fromStorageTypeHelper<PtrType>(ptr); }
@@ -132,11 +136,7 @@ private:
 #else
     PtrType fromStorageType(StorageType ptr) const
     {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-        // FIXME: Bug 177895: Re-enable -Wcast-qual for Apple ports.
-        return (PtrType)ptr;
-#pragma clang diagnostic pop
+        return (PtrType)const_cast<CF_BRIDGED_TYPE(id) void*>(ptr);
     }
     StorageType toStorageType(PtrType ptr) const { return (StorageType)ptr; }
 #endif
index d525894..e34fd6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef TypeCastsCF_h
-#define TypeCastsCF_h
+#pragma once
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <wtf/Assertions.h>
 
+#ifndef CF_BRIDGED_TYPE
+#define CF_BRIDGED_TYPE(T)
+#endif
+
 namespace WTF {
 
 template <typename> struct CFTypeTrait;
 
-#define DECLARE_CF_TYPE_TRAIT(ClassName) \
+#define WTF_DECLARE_CF_TYPE_TRAIT(ClassName) \
+template <> \
+struct WTF::CFTypeTrait<ClassName##Ref> { \
+    static inline CFTypeID typeID(void) { return ClassName##GetTypeID(); } \
+};
+
+WTF_DECLARE_CF_TYPE_TRAIT(CFArray);
+WTF_DECLARE_CF_TYPE_TRAIT(CFBoolean);
+WTF_DECLARE_CF_TYPE_TRAIT(CFData);
+WTF_DECLARE_CF_TYPE_TRAIT(CFDictionary);
+WTF_DECLARE_CF_TYPE_TRAIT(CFNumber);
+WTF_DECLARE_CF_TYPE_TRAIT(CFString);
+
+#define WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(ClassName, MutableClassName) \
 template <> \
-struct CFTypeTrait<ClassName##Ref> { \
-    static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \
+struct WTF::CFTypeTrait<MutableClassName##Ref> { \
+    static inline CFTypeID typeID(void) { return ClassName##GetTypeID(); } \
 };
 
-DECLARE_CF_TYPE_TRAIT(CFArray);
-DECLARE_CF_TYPE_TRAIT(CFBoolean);
-DECLARE_CF_TYPE_TRAIT(CFData);
-DECLARE_CF_TYPE_TRAIT(CFDictionary);
-DECLARE_CF_TYPE_TRAIT(CFNumber);
-DECLARE_CF_TYPE_TRAIT(CFString);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFArray, CFMutableArray);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFData, CFMutableData);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFDictionary, CFMutableDictionary);
+WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT(CFString, CFMutableString);
 
-#undef DECLARE_CF_TYPE_TRAIT
+#undef WTF_DECLARE_CF_MUTABLE_TYPE_TRAIT
 
 template<typename T> T dynamic_cf_cast(CFTypeRef object)
 {
     if (!object)
         return nullptr;
 
+    ASSERT_WITH_SECURITY_IMPLICATION(CFGetTypeID(object) == CFTypeTrait<T>::typeID());
     if (CFGetTypeID(object) != CFTypeTrait<T>::typeID())
         return nullptr;
 
-    return static_cast<T>(object);
+    return static_cast<T>(const_cast<CF_BRIDGED_TYPE(id) void*>(object));
 }
 
 template<typename T> T checked_cf_cast(CFTypeRef object)
 {
-    auto result = dynamic_cf_cast<T>(object);
-    ASSERT_WITH_SECURITY_IMPLICATION(result);
+    if (!object)
+        return nullptr;
 
-    return result;
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(CFGetTypeID(object) == CFTypeTrait<T>::typeID());
+
+    return static_cast<T>(const_cast<CF_BRIDGED_TYPE(id) void*>(object));
 }
 
 } // namespace WTF
 
 using WTF::checked_cf_cast;
 using WTF::dynamic_cf_cast;
-
-#endif // TypeCastsCF_h
index c60509c..c28825c 100644 (file)
@@ -1,3 +1,102 @@
+2018-01-05  David Kilzer  <ddkilzer@apple.com>
+
+        Re-enable -Wcast-qual in WebCore for Apple ports
+        <https://webkit.org/b/177895>
+        <rdar://problem/34960830>
+
+        Reviewed by Joseph Pecoraro.
+
+        * Configurations/Base.xcconfig:
+        (WARNING_CFLAGS): Remove FIXME and add -Wcast-qual back to
+        arguments.
+
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm:
+        (WebCore::createAndStoreMasterKey):
+        - Use checked_cf_cast<SecACLRef>().
+
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::detectItemAtPositionWithRange):
+        - Manually cast CFTypeRef to DDResultRef until
+          DDResultGetTypeID() is available as SPI.
+
+        * platform/gamepad/mac/HIDGamepad.cpp:
+        (WebCore::HIDGamepad::initElementsFromArray):
+        - Use checked_cf_cast<IOHIDElementRef>().
+
+        * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
+        (WebCore::MediaSampleAVFObjC::createImageSample):
+        (WebCore::CMSampleBufferIsRandomAccess):
+        (WebCore::CMSampleBufferIsNonDisplaying):
+        (WebCore::MediaSampleAVFObjC::createNonDisplayingCopy const):
+        - Use checked_cf_cast<CFMutableDictionaryRef>() and
+          checked_cf_cast<CFDictionaryRef>().
+
+        * platform/graphics/cocoa/IOSurface.h:
+        (WebCore::IOSurface::asLayerContents):
+        - Use reinterpret_cast<id>() to cast from IOSurfaceRef to id.
+
+        * platform/graphics/cocoa/WebCoreDecompressionSession.mm:
+        (WebCore::WebCoreDecompressionSession::getFirstVideoFrame):
+        (WebCore::WebCoreDecompressionSession::automaticDequeue):
+        (WebCore::WebCoreDecompressionSession::imageForTime):
+        (WebCore::WebCoreDecompressionSession::getDecodeTime):
+        (WebCore::WebCoreDecompressionSession::getPresentationTime):
+        (WebCore::WebCoreDecompressionSession::getDuration):
+        - Use checked_cf_cast<CMSampleBufferRef>().
+
+        * platform/graphics/Font.h:
+        (WebCore::Font::m_kernedCFStringAttributes):
+        (WebCore::Font::m_nonKernedCFStringAttributes):
+        - Change type from RetainPtr<CFDictionaryRef> to
+          RetainPtr<CFMutableDictionaryRef> since that's what they are.
+        * platform/graphics/mac/SimpleFontDataCoreText.cpp:
+        (WebCore::Font::getCFStringAttributes const):
+        - Replace local `mutableAttributes` variable with
+          `attributesDictionary.get()` since it returns the correct type
+          now.
+
+        * platform/ios/wak/WAKView.mm:
+        (-[WAKView _initWithViewRef:]):
+        (_WAKCopyWrapper):
+        * platform/ios/wak/WKView.mm:
+        (_WKViewClearSuperview):
+        (WKViewFirstChild):
+        (WKViewNextSibling):
+        - Use static_cast<WKViewRef>(const_cast<void*>()) to convert
+          const void* variable to WKViewRef.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::flipImageSpec):
+        (WebCore::setDragImageImpl):
+        - Use const_cast<> to remove 'const' modifier from
+          unsigned char pointers.  This regressed while -Wcast-qual was
+          disabled for WebCore.
+
+        * platform/mac/SSLKeyGeneratorMac.mm:
+        (WebCore::signedPublicKeyAndChallengeString):
+        - Use checked_cf_cast<SecACLRef>().
+
+        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp:
+        (WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):
+        - Use checked_cf_cast<CFMutableDictionaryRef>().
+
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::copyCONNECTProxyResponse):
+        - Use checked_cf_cast<CFHTTPMessageRef>().
+
+        * platform/network/cocoa/ResourceResponseCocoa.mm:
+        (WebCore::ResourceResponse::platformCertificateInfo const):
+        - Use checked_cf_cast<SecTrustRef>().
+
+        * platform/network/mac/CertificateInfoMac.mm:
+        (WebCore::CertificateInfo::containsNonRootSHA1SignedCertificate const):
+        (WebCore::CertificateInfo::dump const):
+        - Use checked_cf_cast<SecCertificateRef>().
+
+        * testing/cocoa/WebArchiveDumpSupport.mm:
+        (WebCoreTestSupport::createCFURLResponseFromResponseData):
+        - Use checked_cf_cast<>() for CFMutable* types.
+
 2018-01-05  John Wilander  <wilander@apple.com>
 
         Storage Access API: Refactor to make naming accurate and explicit, simplify access table, and prepare for access removal for page
index 8f69cda..4c6fab3 100644 (file)
@@ -80,8 +80,7 @@ GCC_WARN_SIGN_COMPARE = YES;
 GCC_WARN_UNINITIALIZED_AUTOS = YES;
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
-// FIXME: Bug 177895: Re-enable -Wcast-qual for Apple ports.
-WARNING_CFLAGS = -Wall -Wextra -Wchar-subscripts -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wno-unknown-warning-option;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wno-unknown-warning-option;
 
 TARGET_MAC_OS_X_VERSION_MAJOR = $(TARGET_MAC_OS_X_VERSION_MAJOR$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier));
 TARGET_MAC_OS_X_VERSION_MAJOR_11 = 101100;
index 2b30a0f..eaca89d 100644 (file)
 #define USE_KEYCHAIN_ACCESS_CONTROL_LISTS 1
 #endif
 
+#if USE(KEYCHAIN_ACCESS_CONTROL_LISTS)
+#include <wtf/cf/TypeCastsCF.h>
+WTF_DECLARE_CF_TYPE_TRAIT(SecACL);
+#endif
+
 namespace WebCore {
 
 const NSUInteger currentSerializationVersion = 1;
@@ -103,7 +108,7 @@ static bool createAndStoreMasterKey(Vector<uint8_t>& masterKeyData)
     RetainPtr<SecAccessRef> access = adoptCF(accessRef);
 
     RetainPtr<CFArrayRef> acls = adoptCF(SecAccessCopyMatchingACLList(accessRef, kSecACLAuthorizationExportClear));
-    SecACLRef acl = (SecACLRef)CFArrayGetValueAtIndex(acls.get(), 0);
+    SecACLRef acl = checked_cf_cast<SecACLRef>(CFArrayGetValueAtIndex(acls.get(), 0));
 
     SecTrustedApplicationRef trustedAppRef;
     status = SecTrustedApplicationCreateFromPath(0, &trustedAppRef);
index f3e67e5..f445616 100644 (file)
@@ -78,7 +78,8 @@ static RetainPtr<DDActionContext> detectItemAtPositionWithRange(VisiblePosition
     RefPtr<Range> mainResultRange;
     CFIndex resultCount = CFArrayGetCount(results.get());
     for (CFIndex i = 0; i < resultCount; i++) {
-        DDResultRef result = (DDResultRef)CFArrayGetValueAtIndex(results.get(), i);
+        // FIXME: <rdar://problem/36241894> Implement checked cast for DDResultRef once DDResultGetTypeID() is available
+        DDResultRef result = static_cast<DDResultRef>(const_cast<CF_BRIDGED_TYPE(id) void*>(CFArrayGetValueAtIndex(results.get(), i)));
         CFRange resultRangeInContext = DDResultGetRange(result);
         if (hitLocation >= resultRangeInContext.location && (hitLocation - resultRangeInContext.location) < resultRangeInContext.length) {
             mainResult = result;
index 68e8e81..f86cf16 100644 (file)
 #include <IOKit/hid/IOHIDUsageTables.h>
 #include <IOKit/hid/IOHIDValue.h>
 #include <wtf/CurrentTime.h>
+#include <wtf/cf/TypeCastsCF.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(IOHIDElement);
+
 namespace WebCore {
 
 HIDGamepad::HIDGamepad(IOHIDDeviceRef hidDevice, unsigned index)
@@ -94,7 +97,7 @@ void HIDGamepad::initElements()
 void HIDGamepad::initElementsFromArray(CFArrayRef elements)
 {
     for (CFIndex i = 0, count = CFArrayGetCount(elements); i < count; ++i) {
-        IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
+        IOHIDElementRef element = checked_cf_cast<IOHIDElementRef>(CFArrayGetValueAtIndex(elements, i));
         if (CFGetTypeID(element) != IOHIDElementGetTypeID())
             continue;
 
index a663023..ed432ed 100644 (file)
@@ -289,8 +289,8 @@ private:
 #endif
 
 #if PLATFORM(COCOA)
-    mutable RetainPtr<CFDictionaryRef> m_nonKernedCFStringAttributes;
-    mutable RetainPtr<CFDictionaryRef> m_kernedCFStringAttributes;
+    mutable RetainPtr<CFMutableDictionaryRef> m_nonKernedCFStringAttributes;
+    mutable RetainPtr<CFMutableDictionaryRef> m_kernedCFStringAttributes;
     mutable std::optional<BitVector> m_glyphsSupportedBySmallCaps;
     mutable std::optional<BitVector> m_glyphsSupportedByAllSmallCaps;
     mutable std::optional<BitVector> m_glyphsSupportedByPetiteCaps;
index 55d7b55..fb52c75 100644 (file)
 #import <runtime/JSCInlines.h>
 #import <runtime/TypedArrayInlines.h>
 #import <wtf/PrintStream.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 #import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
 
-namespace WebCore {
 using namespace PAL;
 
+WTF_DECLARE_CF_TYPE_TRAIT(CMSampleBuffer);
+
+namespace WebCore {
+
 static inline void releaseUint8Vector(void *array, const void*)
 {
     adoptMallocPtr(static_cast<uint8_t*>(array));
@@ -67,7 +71,7 @@ RefPtr<MediaSampleAVFObjC> MediaSampleAVFObjC::createImageSample(Vector<uint8_t>
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sample.get(), true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
     }
     return create(sample.get());
@@ -116,7 +120,7 @@ static bool CMSampleBufferIsRandomAccess(CMSampleBufferRef sample)
         return true;
     
     for (CFIndex i = 0, count = CFArrayGetCount(attachments); i < count; ++i) {
-        CFDictionaryRef attachmentDict = (CFDictionaryRef)CFArrayGetValueAtIndex(attachments, i);
+        CFDictionaryRef attachmentDict = checked_cf_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(attachments, i));
         if (CFDictionaryContainsKey(attachmentDict, kCMSampleAttachmentKey_NotSync))
             return false;
     }
@@ -130,7 +134,7 @@ static bool CMSampleBufferIsNonDisplaying(CMSampleBufferRef sample)
         return false;
     
     for (CFIndex i = 0; i < CFArrayGetCount(attachments); ++i) {
-        CFDictionaryRef attachmentDict = (CFDictionaryRef)CFArrayGetValueAtIndex(attachments, i);
+        CFDictionaryRef attachmentDict = checked_cf_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(attachments, i));
         if (CFDictionaryContainsKey(attachmentDict, kCMSampleAttachmentKey_DoNotDisplay))
             return true;
     }
@@ -266,7 +270,7 @@ Ref<MediaSample> MediaSampleAVFObjC::createNonDisplayingCopy() const
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(newSampleBuffer, true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DoNotDisplay, kCFBooleanTrue);
     }
 
index 702a094..6decad6 100644 (file)
@@ -101,7 +101,7 @@ public:
     WEBCORE_EXPORT RetainPtr<CGImageRef> createImage();
     WEBCORE_EXPORT static RetainPtr<CGImageRef> sinkIntoImage(std::unique_ptr<IOSurface>);
 
-    id asLayerContents() const { return (id)(CFTypeRef)m_surface.get(); }
+    id asLayerContents() const { return reinterpret_cast<id>(m_surface.get()); }
     IOSurfaceRef surface() const { return m_surface.get(); }
     WEBCORE_EXPORT GraphicsContext& ensureGraphicsContext();
     WEBCORE_EXPORT CGContextRef ensurePlatformContext();
index dd9f2f9..1752f45 100644 (file)
 #import <wtf/MediaTime.h>
 #import <wtf/StringPrintStream.h>
 #import <wtf/Vector.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 #import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
 #import "VideoToolboxSoftLink.h"
 
-namespace WebCore {
 using namespace PAL;
 
+WTF_DECLARE_CF_TYPE_TRAIT(CMSampleBuffer);
+
+namespace WebCore {
+
 WebCoreDecompressionSession::WebCoreDecompressionSession(Mode mode)
     : m_mode(mode)
     , m_decompressionQueue(adoptOSObject(dispatch_queue_create("WebCoreDecompressionSession Decompression Queue", DISPATCH_QUEUE_SERIAL)))
@@ -322,7 +326,7 @@ RetainPtr<CVPixelBufferRef> WebCoreDecompressionSession::getFirstVideoFrame()
     if (!m_producerQueue || CMBufferQueueIsEmpty(m_producerQueue.get()))
         return nullptr;
 
-    RetainPtr<CMSampleBufferRef> currentSample = adoptCF((CMSampleBufferRef)CMBufferQueueDequeueAndRetain(m_producerQueue.get()));
+    RetainPtr<CMSampleBufferRef> currentSample = adoptCF(checked_cf_cast<CMSampleBufferRef>(CMBufferQueueDequeueAndRetain(m_producerQueue.get())));
     RetainPtr<CVPixelBufferRef> imageBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(currentSample.get());
     ASSERT(CFGetTypeID(imageBuffer.get()) == CVPixelBufferGetTypeID());
 
@@ -342,7 +346,7 @@ void WebCoreDecompressionSession::automaticDequeue()
     MediaTime nextFireTime = MediaTime::positiveInfiniteTime();
     bool releasedImageBuffers = false;
 
-    while (CMSampleBufferRef firstSample = (CMSampleBufferRef)CMBufferQueueGetHead(m_producerQueue.get())) {
+    while (CMSampleBufferRef firstSample = checked_cf_cast<CMSampleBufferRef>(CMBufferQueueGetHead(m_producerQueue.get()))) {
         MediaTime presentationTimestamp = PAL::toMediaTime(CMSampleBufferGetPresentationTimeStamp(firstSample));
         MediaTime duration = PAL::toMediaTime(CMSampleBufferGetDuration(firstSample));
         MediaTime presentationEndTimestamp = presentationTimestamp + duration;
@@ -481,7 +485,7 @@ RetainPtr<CVPixelBufferRef> WebCoreDecompressionSession::imageForTime(const Medi
 
     bool releasedImageBuffers = false;
 
-    while (CMSampleBufferRef firstSample = (CMSampleBufferRef)CMBufferQueueGetHead(m_producerQueue.get())) {
+    while (CMSampleBufferRef firstSample = checked_cf_cast<CMSampleBufferRef>(CMBufferQueueGetHead(m_producerQueue.get()))) {
         MediaTime presentationTimestamp = PAL::toMediaTime(CMSampleBufferGetPresentationTimeStamp(firstSample));
         MediaTime duration = PAL::toMediaTime(CMSampleBufferGetDuration(firstSample));
         MediaTime presentationEndTimestamp = presentationTimestamp + duration;
@@ -493,7 +497,7 @@ RetainPtr<CVPixelBufferRef> WebCoreDecompressionSession::imageForTime(const Medi
             continue;
         }
 
-        RetainPtr<CMSampleBufferRef> currentSample = adoptCF((CMSampleBufferRef)CMBufferQueueDequeueAndRetain(m_producerQueue.get()));
+        RetainPtr<CMSampleBufferRef> currentSample = adoptCF(checked_cf_cast<CMSampleBufferRef>(CMBufferQueueDequeueAndRetain(m_producerQueue.get())));
         RetainPtr<CVPixelBufferRef> imageBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(currentSample.get());
         ASSERT(CFGetTypeID(imageBuffer.get()) == CVPixelBufferGetTypeID());
 
@@ -531,22 +535,19 @@ void WebCoreDecompressionSession::flush()
 
 CMTime WebCoreDecompressionSession::getDecodeTime(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetDecodeTimeStamp(sample);
 }
 
 CMTime WebCoreDecompressionSession::getPresentationTime(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetPresentationTimeStamp(sample);
 }
 
 CMTime WebCoreDecompressionSession::getDuration(CMBufferRef buf, void*)
 {
-    ASSERT(CFGetTypeID(buf) == CMSampleBufferGetTypeID());
-    CMSampleBufferRef sample = (CMSampleBufferRef)(buf);
+    CMSampleBufferRef sample = checked_cf_cast<CMSampleBufferRef>(buf);
     return CMSampleBufferGetDuration(sample);
 }
 
index 91f67f0..8109d49 100644 (file)
@@ -42,18 +42,17 @@ CFDictionaryRef Font::getCFStringAttributes(bool enableKerning, FontOrientation
         return attributesDictionary.get();
 
     attributesDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    CFMutableDictionaryRef mutableAttributes = (CFMutableDictionaryRef)attributesDictionary.get();
 
-    CFDictionarySetValue(mutableAttributes, kCTFontAttributeName, platformData().ctFont());
+    CFDictionarySetValue(attributesDictionary.get(), kCTFontAttributeName, platformData().ctFont());
 
     if (!enableKerning) {
         const float zero = 0;
         static CFNumberRef zeroKerningValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero);
-        CFDictionarySetValue(mutableAttributes, kCTKernAttributeName, zeroKerningValue);
+        CFDictionarySetValue(attributesDictionary.get(), kCTKernAttributeName, zeroKerningValue);
     }
 
     if (orientation == Vertical)
-        CFDictionarySetValue(mutableAttributes, kCTVerticalFormsAttributeName, kCFBooleanTrue);
+        CFDictionarySetValue(attributesDictionary.get(), kCTVerticalFormsAttributeName, kCFBooleanTrue);
 
     return attributesDictionary.get();
 }
index fd2f852..42dc048 100644 (file)
@@ -221,7 +221,7 @@ static void invalidateGStateCallback(WKViewRef view)
     if (!self)
         return nil;
 
-    viewRef = (WKViewRef)WKRetain (viewR);
+    viewRef = static_cast<WKViewRef>(const_cast<void*>(WKRetain(viewR)));
     viewRef->wrapper = (void *)self;
 
     return self;
@@ -288,7 +288,7 @@ static void _WAKCopyWrapper(const void *value, void *context)
         return;
     
     NSMutableArray *array = (NSMutableArray *)context;
-    WAKView *view = WAKViewForWKViewRef((WKViewRef)value);
+    WAKView *view = WAKViewForWKViewRef(static_cast<WKViewRef>(const_cast<void*>(value)));
     if (view)
         [array addObject:view];
 }
index a7c7172..e0f9ebc 100644 (file)
@@ -73,7 +73,7 @@ void _WKViewSetWindow (WKViewRef view, WAKWindow *window)
 static void _WKViewClearSuperview(const void *value, void *context)
 {
     UNUSED_PARAM(context);
-    _WKViewSetSuperview((WKViewRef)value, 0);
+    _WKViewSetSuperview(static_cast<WKViewRef>(const_cast<void*>(value)), 0);
 }
 
 static void _WKViewDealloc (WKObjectRef v)
@@ -105,7 +105,7 @@ WKClassInfo WKViewClassInfo = { &WKObjectClass, "WKView", _WKViewDealloc };
 
 WKViewRef WKViewCreateWithFrame (CGRect frame, WKViewContext *context)
 {
-    WKViewRef view = (WKViewRef)WKCreateObjectWithSize (sizeof(struct _WKView), &WKViewClassInfo);
+    WKViewRef view = static_cast<WKViewRef>(const_cast<void*>(WKCreateObjectWithSize(sizeof(struct _WKView), &WKViewClassInfo)));
     if (!view)
         return 0;
     
@@ -468,7 +468,7 @@ WKViewRef WKViewFirstChild (WKViewRef view)
     if (!count)
         return 0;
         
-    return (const WKViewRef)CFArrayGetValueAtIndex (sv, 0);
+    return static_cast<WKViewRef>(const_cast<void*>(CFArrayGetValueAtIndex(sv, 0)));
 }
 
 WKViewRef WKViewNextSibling (WKViewRef view)
@@ -495,7 +495,7 @@ WKViewRef WKViewNextSibling (WKViewRef view)
     if (thisIndex+1 >= count)
         return 0;
         
-    return (const WKViewRef)CFArrayGetValueAtIndex (svs, thisIndex+1);
+    return static_cast<WKViewRef>(const_cast<void*>(CFArrayGetValueAtIndex(svs, thisIndex + 1)));
 }
 
 // To remove, see: <rdar://problem/10360425> Remove WKViewTraverseNext from Skankphone
index b61b5e8..c26c904 100644 (file)
@@ -575,7 +575,7 @@ static void flipImageSpec(CoreDragImageSpec* imageSpec)
     int planes = imageSpec->isPlanar ? imageSpec->samplesPerPixel : 1;
 
     for (int p = 0; p < planes; ++p) {
-        unsigned char* topRow = (unsigned char*)imageSpec->data[p];
+        unsigned char* topRow = const_cast<unsigned char*>(imageSpec->data[p]);
         unsigned char* botRow = topRow + (imageSpec->pixelsHigh - 1) * imageSpec->bytesPerRow;
         for (int i = 0; i < imageSpec->pixelsHigh / 2; ++i, topRow += imageSpec->bytesPerRow, botRow -= imageSpec->bytesPerRow) {
             bcopy(topRow, tempRow, imageSpec->bytesPerRow);
@@ -624,7 +624,7 @@ static void setDragImageImpl(NSImage *image, NSPoint offset)
     imageSpec.bytesPerRow = [bitmapImage bytesPerRow];
     imageSpec.isPlanar = [bitmapImage isPlanar];
     imageSpec.hasAlpha = [bitmapImage hasAlpha];
-    [bitmapImage getBitmapDataPlanes:(unsigned char**)imageSpec.data];
+    [bitmapImage getBitmapDataPlanes:const_cast<unsigned char**>(imageSpec.data)];
 
     // if image was flipped, we have an upside down bitmap since the cache is rendered flipped
     if (flipImage)
index 3f14f42..98e5f17 100644 (file)
 #import <Security/SecEncodeTransform.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Scope.h>
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/spi/cocoa/SecuritySPI.h>
 #import <wtf/text/Base64.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecACL);
+
 namespace WebCore {
 
 #pragma clang diagnostic push
@@ -138,7 +141,7 @@ static String signedPublicKeyAndChallengeString(unsigned keySize, const CString&
         return String();
     RetainPtr<CFArrayRef> acls = adoptCF(aclsRef);
 
-    SecACLRef acl = (SecACLRef)(CFArrayGetValueAtIndex(acls.get(), 0));
+    SecACLRef acl = checked_cf_cast<SecACLRef>(CFArrayGetValueAtIndex(acls.get(), 0));
 
     // Passing nullptr to SecTrustedApplicationCreateFromPath tells that function to assume the application bundle.
     SecTrustedApplicationRef trustedAppRef { nullptr };
index 4cfe23d..ca9aac4 100644 (file)
@@ -33,6 +33,7 @@
 #include "Logging.h"
 #include "MediaSampleAVFObjC.h"
 #include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
+#include <wtf/cf/TypeCastsCF.h>
 
 #include <pal/cf/CoreMediaSoftLink.h>
 #include "CoreVideoSoftLink.h"
@@ -124,7 +125,7 @@ void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
 
     CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
     for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
-        CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+        CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
     }
 
index 0486404..76ff83b 100644 (file)
@@ -45,6 +45,7 @@
 #include <wtf/Lock.h>
 #include <wtf/MainThread.h>
 #include <wtf/SoftLinking.h>
+#include <wtf/cf/TypeCastsCF.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(WIN)
@@ -66,6 +67,8 @@ SOFT_LINK_LIBRARY(CFNetwork);
 SOFT_LINK_OPTIONAL(CFNetwork, _CFHTTPMessageSetResponseProxyURL, void, __cdecl, (CFHTTPMessageRef, CFURLRef));
 #endif
 
+WTF_DECLARE_CF_TYPE_TRAIT(CFHTTPMessage);
+
 namespace WebCore {
 
 SocketStreamHandleImpl::SocketStreamHandleImpl(const URL& url, SocketStreamHandleClient& client, PAL::SessionID sessionID, const String& credentialPartition, SourceApplicationAuditToken&& auditData)
@@ -505,7 +508,7 @@ static void setResponseProxyURL(CFHTTPMessageRef message, CFURLRef proxyURL)
 
 static RetainPtr<CFHTTPMessageRef> copyCONNECTProxyResponse(CFReadStreamRef stream, CFURLRef responseURL, CFStringRef proxyHost, CFNumberRef proxyPort)
 {
-    auto message = adoptCF((CFHTTPMessageRef)CFReadStreamCopyProperty(stream, kCFStreamPropertyCONNECTResponse));
+    auto message = adoptCF(checked_cf_cast<CFHTTPMessageRef>(CFReadStreamCopyProperty(stream, kCFStreamPropertyCONNECTResponse)));
     // CFNetwork needs URL to be set on response in order to handle authentication - even though it doesn't seem to make sense to provide ultimate target URL when authenticating to a proxy.
     // This is set by CFNetwork internally for normal HTTP responses, but not for proxies.
     _CFHTTPMessageSetResponseURL(message.get(), responseURL);
index 25ff75f..c739630 100644 (file)
 #import <wtf/AutodrainedPool.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/StdLibExtras.h>
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/text/StringView.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecTrust);
+
 namespace WebCore {
 
 void ResourceResponse::initNSURLResponse() const
@@ -88,8 +91,7 @@ CertificateInfo ResourceResponse::platformCertificateInfo() const
     auto trustValue = CFDictionaryGetValue(context, kCFStreamPropertySSLPeerTrust);
     if (!trustValue)
         return { };
-    ASSERT(CFGetTypeID(trustValue) == SecTrustGetTypeID());
-    auto trust = (SecTrustRef)trustValue;
+    auto trust = checked_cf_cast<SecTrustRef>(trustValue);
 
     SecTrustResultType trustResultType;
     OSStatus result = SecTrustGetTrustResult(trust, &trustResultType);
index e6bad6e..ffc99be 100644 (file)
 #import "CertificateInfo.h"
 
 #import "NotImplemented.h"
+#import <wtf/cf/TypeCastsCF.h>
 #import <wtf/spi/cocoa/SecuritySPI.h>
 
+WTF_DECLARE_CF_TYPE_TRAIT(SecCertificate);
+
 namespace WebCore {
 
 #if PLATFORM(COCOA)
@@ -84,7 +87,7 @@ bool CertificateInfo::containsNonRootSHA1SignedCertificate() const
     if (m_certificateChain) {
         // Allow only the root certificate (the last in the chain) to be SHA1.
         for (CFIndex i = 0, size = CFArrayGetCount(m_certificateChain.get()) - 1; i < size; ++i) {
-            auto certificate = (SecCertificateRef)CFArrayGetValueAtIndex(m_certificateChain.get(), i);
+            auto certificate = checked_cf_cast<SecCertificateRef>(CFArrayGetValueAtIndex(m_certificateChain.get(), i));
             if (SecCertificateGetSignatureHashAlgorithm(certificate) == kSecSignatureHashAlgorithmSHA1)
                 return true;
         }
@@ -117,7 +120,7 @@ void CertificateInfo::dump() const
         NSLog(@"CertificateInfo (Certificate Chain)\n");
         NSLog(@"  Entries: %ld\n", entries);
         for (CFIndex i = 0; i < entries; ++i) {
-            RetainPtr<CFStringRef> summary = adoptCF(SecCertificateCopySubjectSummary((SecCertificateRef)CFArrayGetValueAtIndex(m_certificateChain.get(), i)));
+            RetainPtr<CFStringRef> summary = adoptCF(SecCertificateCopySubjectSummary(checked_cf_cast<SecCertificateRef>(CFArrayGetValueAtIndex(m_certificateChain.get(), i))));
             NSLog(@"  %@", (NSString *)summary.get());
         }
 
index fceab76..7459669 100644 (file)
@@ -34,6 +34,7 @@
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 using namespace WebCore;
 
@@ -90,7 +91,7 @@ static void convertMIMEType(CFMutableStringRef mimeType)
 
 static void convertWebResourceDataToString(CFMutableDictionaryRef resource)
 {
-    CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType"));
+    CFMutableStringRef mimeType = checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType")));
     CFStringLowercase(mimeType, CFLocaleGetSystem());
     convertMIMEType(mimeType);
 
@@ -219,7 +220,7 @@ CFStringRef createXMLStringFromWebArchiveData(CFDataRef webArchiveData)
 {
     CFErrorRef error = 0;
     CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
-    RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF((CFMutableDictionaryRef)CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error));
+    RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF(checked_cf_cast<CFMutableDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error)));
 
     if (!propertyList) {
         if (error)
@@ -231,26 +232,26 @@ CFStringRef createXMLStringFromWebArchiveData(CFDataRef webArchiveData)
     CFArrayAppendValue(resources.get(), propertyList.get());
 
     while (CFArrayGetCount(resources.get())) {
-        RetainPtr<CFMutableDictionaryRef> resourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(resources.get(), 0);
+        RetainPtr<CFMutableDictionaryRef> resourcePropertyList = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(resources.get(), 0));
         CFArrayRemoveValueAtIndex(resources.get(), 0);
 
-        CFMutableDictionaryRef mainResource = (CFMutableDictionaryRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebMainResource"));
-        normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(mainResource, CFSTR("WebResourceURL")));
+        CFMutableDictionaryRef mainResource = checked_cf_cast<CFMutableDictionaryRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebMainResource")));
+        normalizeWebResourceURL(checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(mainResource, CFSTR("WebResourceURL"))));
         convertWebResourceDataToString(mainResource);
 
         // Add subframeArchives to list for processing
-        CFMutableArrayRef subframeArchives = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubframeArchives")); // WebSubframeArchivesKey in WebArchive.m
+        CFMutableArrayRef subframeArchives = checked_cf_cast<CFMutableArrayRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubframeArchives"))); // WebSubframeArchivesKey in WebArchive.m
         if (subframeArchives)
             CFArrayAppendArray(resources.get(), subframeArchives, CFRangeMake(0, CFArrayGetCount(subframeArchives)));
 
-        CFMutableArrayRef subresources = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubresources")); // WebSubresourcesKey in WebArchive.m
+        CFMutableArrayRef subresources = checked_cf_cast<CFMutableArrayRef>(CFDictionaryGetValue(resourcePropertyList.get(), CFSTR("WebSubresources"))); // WebSubresourcesKey in WebArchive.m
         if (!subresources)
             continue;
 
         CFIndex subresourcesCount = CFArrayGetCount(subresources);
         for (CFIndex i = 0; i < subresourcesCount; ++i) {
-            CFMutableDictionaryRef subresourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(subresources, i);
-            normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(subresourcePropertyList, CFSTR("WebResourceURL")));
+            CFMutableDictionaryRef subresourcePropertyList = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(subresources, i));
+            normalizeWebResourceURL(checked_cf_cast<CFMutableStringRef>(CFDictionaryGetValue(subresourcePropertyList, CFSTR("WebResourceURL"))));
             convertWebResourceResponseToDictionary(subresourcePropertyList);
             convertWebResourceDataToString(subresourcePropertyList);
         }