Bug 177895 - Re-enable -Wcast-qual in WebCore for Apple ports
Summary: Re-enable -Wcast-qual in WebCore for Apple ports
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on: 177893
Blocks: 181256
  Show dependency treegraph
 
Reported: 2017-10-04 13:07 PDT by David Kilzer (:ddkilzer)
Modified: 2018-01-05 19:20 PST (History)
9 users (show)

See Also:


Attachments
Patch v1 (40.63 KB, patch)
2017-12-31 19:10 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v2 (40.75 KB, patch)
2017-12-31 19:16 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v3 (40.78 KB, patch)
2017-12-31 19:34 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v4 (40.73 KB, patch)
2017-12-31 20:30 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v5 (40.93 KB, patch)
2018-01-01 03:12 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v6 (40.99 KB, patch)
2018-01-01 03:21 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v7 (40.99 KB, patch)
2018-01-01 03:58 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v8 (41.73 KB, patch)
2018-01-01 09:58 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (2.61 MB, application/zip)
2018-01-01 11:20 PST, EWS Watchlist
no flags Details
Patch v9 (41.29 KB, patch)
2018-01-01 18:21 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v10 (41.25 KB, patch)
2018-01-01 20:03 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v11 (41.10 KB, patch)
2018-01-01 22:44 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v12 (48.09 KB, patch)
2018-01-02 21:53 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v13 (41.42 KB, patch)
2018-01-03 09:35 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v14 (43.06 KB, patch)
2018-01-05 13:23 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2017-10-04 13:07:17 PDT
For Bug 177893, we disabled -Wcast-qual in WebCore for Apple ports.

This bug tracks re-enabling it by introducing a safe (and readable) way to cast const CFTypeRef pointers to non-const CFTypeRef pointers (sometimes of a different type).
Comment 1 Radar WebKit Bug Importer 2017-10-12 12:38:29 PDT
<rdar://problem/34960830>
Comment 2 David Kilzer (:ddkilzer) 2017-12-31 19:10:53 PST
Created attachment 330270 [details]
Patch v1
Comment 3 EWS Watchlist 2017-12-31 19:13:17 PST
Attachment 330270 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:32:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:106:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:107:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 4 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 David Kilzer (:ddkilzer) 2017-12-31 19:16:12 PST
Created attachment 330271 [details]
Patch v2
Comment 5 EWS Watchlist 2017-12-31 19:18:35 PST
Attachment 330271 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:106:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:107:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 6 David Kilzer (:ddkilzer) 2017-12-31 19:34:42 PST
Created attachment 330273 [details]
Patch v3
Comment 7 EWS Watchlist 2017-12-31 19:36:34 PST
Attachment 330273 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:106:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:107:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 David Kilzer (:ddkilzer) 2017-12-31 20:30:27 PST
Created attachment 330276 [details]
Patch v4
Comment 9 EWS Watchlist 2017-12-31 20:33:06 PST
Attachment 330276 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:106:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:107:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 David Kilzer (:ddkilzer) 2018-01-01 03:12:48 PST
Created attachment 330282 [details]
Patch v5
Comment 11 EWS Watchlist 2018-01-01 03:15:33 PST
Attachment 330282 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:106:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:107:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 David Kilzer (:ddkilzer) 2018-01-01 03:21:32 PST
Created attachment 330283 [details]
Patch v6
Comment 13 EWS Watchlist 2018-01-01 03:24:37 PST
Attachment 330283 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:63:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:110:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:111:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 14 David Kilzer (:ddkilzer) 2018-01-01 03:58:29 PST
Created attachment 330284 [details]
Patch v7
Comment 15 EWS Watchlist 2018-01-01 04:02:14 PST
Attachment 330284 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:63:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:110:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:111:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 16 David Kilzer (:ddkilzer) 2018-01-01 09:58:53 PST
Created attachment 330286 [details]
Patch v8
Comment 17 EWS Watchlist 2018-01-01 10:01:53 PST
Attachment 330286 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:63:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:110:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:111:  dynamic_id_cast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 3 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 EWS Watchlist 2018-01-01 11:20:48 PST
Comment on attachment 330286 [details]
Patch v8

Attachment 330286 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5885909

New failing tests:
fast/mediastream/MediaStream-MediaElement-setObject-null.html
Comment 19 EWS Watchlist 2018-01-01 11:20:49 PST
Created attachment 330292 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 20 David Kilzer (:ddkilzer) 2018-01-01 18:21:12 PST
Created attachment 330304 [details]
Patch v9
Comment 21 EWS Watchlist 2018-01-01 18:23:40 PST
Attachment 330304 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 22 David Kilzer (:ddkilzer) 2018-01-01 20:03:08 PST
Created attachment 330306 [details]
Patch v10
Comment 23 EWS Watchlist 2018-01-01 20:05:54 PST
Attachment 330306 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 24 David Kilzer (:ddkilzer) 2018-01-01 22:44:34 PST
Created attachment 330309 [details]
Patch v11
Comment 25 EWS Watchlist 2018-01-01 22:47:16 PST
Attachment 330309 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:59:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 26 David Kilzer (:ddkilzer) 2018-01-02 11:16:01 PST
Comment on attachment 330309 [details]
Patch v11

View in context: https://bugs.webkit.org/attachment.cgi?id=330309&action=review

> Source/WTF/ChangeLog:40
> +        (WTF::checked_cf_const_cast): This behaves the same way as
> +        WTF::checked_cf_cast does now, but works with CFTypes that are
> +        not defined as const pointers, including CFMutable types and
> +        other CFTypes defined outside of CoreFoundation.framework.  We
> +        also add built-in support for CFMutable types in the header by
> +        defining traits for them.

Note that I added WTF::checked_cf_const_cast<> so that non-const CFTypes (the CFMutable* types) had a separate method to use.

This makes it harder (in theory) to incorrectly cast to CFArray from CFMutableArray since you must use checked_cf_cast<CFArrayRef>() and checked_cf_const_cast<CFMutableArrayRef>().

In practice, I'm not sure how much this difference matters.  I can just add the const_cast<CF_BRIDGED_TYPE(ID) void*>() to WTF::checked_cf_cast<> and the compiler wouldn't complain about the 'const' being removed and then re-added.
Comment 27 David Kilzer (:ddkilzer) 2018-01-02 11:40:43 PST
(In reply to David Kilzer (:ddkilzer) from comment #26)
> Comment on attachment 330309 [details]
> Patch v11
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=330309&action=review
> 
> > Source/WTF/ChangeLog:40
> > +        (WTF::checked_cf_const_cast): This behaves the same way as
> > +        WTF::checked_cf_cast does now, but works with CFTypes that are
> > +        not defined as const pointers, including CFMutable types and
> > +        other CFTypes defined outside of CoreFoundation.framework.  We
> > +        also add built-in support for CFMutable types in the header by
> > +        defining traits for them.
> 
> Note that I added WTF::checked_cf_const_cast<> so that non-const CFTypes
> (the CFMutable* types) had a separate method to use.
> 
> This makes it harder (in theory) to incorrectly cast to CFArray from
> CFMutableArray since you must use checked_cf_cast<CFArrayRef>() and
> checked_cf_const_cast<CFMutableArrayRef>().
> 
> In practice, I'm not sure how much this difference matters.  I can just add
> the const_cast<CF_BRIDGED_TYPE(ID) void*>() to WTF::checked_cf_cast<> and
> the compiler wouldn't complain about the 'const' being removed and then
> re-added.

And I can check that CFMutable* objects are actually mutable using something like this (which would be a Debug assertion to start with since there is no security implication):

inline bool CFArrayIsMutable(CFArrayRef array)
{
    return [(id)array isMemberOfClass:[NSMutableArray class]];
}
Comment 28 David Kilzer (:ddkilzer) 2018-01-02 21:53:11 PST
Created attachment 330366 [details]
Patch v12
Comment 29 EWS Watchlist 2018-01-02 21:55:51 PST
Attachment 330366 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:84:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 30 David Kilzer (:ddkilzer) 2018-01-02 21:56:30 PST
(In reply to David Kilzer (:ddkilzer) from comment #27)
> (In reply to David Kilzer (:ddkilzer) from comment #26)
> > Comment on attachment 330309 [details]
> > Patch v11
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=330309&action=review
> > 
> > > Source/WTF/ChangeLog:40
> > > +        (WTF::checked_cf_const_cast): This behaves the same way as
> > > +        WTF::checked_cf_cast does now, but works with CFTypes that are
> > > +        not defined as const pointers, including CFMutable types and
> > > +        other CFTypes defined outside of CoreFoundation.framework.  We
> > > +        also add built-in support for CFMutable types in the header by
> > > +        defining traits for them.
> > 
> > Note that I added WTF::checked_cf_const_cast<> so that non-const CFTypes
> > (the CFMutable* types) had a separate method to use.
> > 
> > This makes it harder (in theory) to incorrectly cast to CFArray from
> > CFMutableArray since you must use checked_cf_cast<CFArrayRef>() and
> > checked_cf_const_cast<CFMutableArrayRef>().
> > 
> > In practice, I'm not sure how much this difference matters.  I can just add
> > the const_cast<CF_BRIDGED_TYPE(ID) void*>() to WTF::checked_cf_cast<> and
> > the compiler wouldn't complain about the 'const' being removed and then
> > re-added.
> 
> And I can check that CFMutable* objects are actually mutable using something
> like this (which would be a Debug assertion to start with since there is no
> security implication):
> 
> inline bool CFArrayIsMutable(CFArrayRef array)
> {
>     return [(id)array isMemberOfClass:[NSMutableArray class]];
> }

Actually this won't work, so will need to make more changes.
Comment 31 David Kilzer (:ddkilzer) 2018-01-03 09:35:38 PST
Created attachment 330394 [details]
Patch v13
Comment 32 EWS Watchlist 2018-01-03 09:38:47 PST
Attachment 330394 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:70:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 21 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 33 David Kilzer (:ddkilzer) 2018-01-03 13:08:50 PST
(In reply to David Kilzer (:ddkilzer) from comment #31)
> Created attachment 330394 [details]
> Patch v13

Okay, I'm done iterating on this.  It's ready for review.
Comment 34 Joseph Pecoraro 2018-01-03 14:17:22 PST
Comment on attachment 330394 [details]
Patch v13

View in context: https://bugs.webkit.org/attachment.cgi?id=330394&action=review

Looks good to me. I didn't really understand the RetainPtr changes though so I'll let someone else review.

> Source/WTF/ChangeLog:30
> +        Release buidls, as well as other "checked" functions.

Typo: "buidls" => "builds"

> Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp:47
>      attributesDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
> -    CFMutableDictionaryRef mutableAttributes = (CFMutableDictionaryRef)attributesDictionary.get();
> +    CFMutableDictionaryRef mutableAttributes = checked_cf_cast<CFMutableDictionaryRef>(attributesDictionary.get());

Here I'd probably just switch to using `attributesDictionary.get()` locally instead of `mutableAttributes`. This is a local we just created on line 46, we shouldn't need to check its type.

> Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm:223
> -    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)));

For these WebArchive cases, I think that if we got an unexpected type that we would want to bail with an error message instead of crashing (inside a cast check). That said the checked casts are certainly better then previous behavior.
Comment 35 David Kilzer (:ddkilzer) 2018-01-05 11:49:04 PST
Comment on attachment 330394 [details]
Patch v13

View in context: https://bugs.webkit.org/attachment.cgi?id=330394&action=review

>> Source/WTF/ChangeLog:30
>> +        Release buidls, as well as other "checked" functions.
> 
> Typo: "buidls" => "builds"

Fixed.  Thanks for spotting this!

>> Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp:47
>> +    CFMutableDictionaryRef mutableAttributes = checked_cf_cast<CFMutableDictionaryRef>(attributesDictionary.get());
> 
> Here I'd probably just switch to using `attributesDictionary.get()` locally instead of `mutableAttributes`. This is a local we just created on line 46, we shouldn't need to check its type.

Done!  Had to change the type of m_kernedCFStringAttributes and m_nonKernedCFStringAttributes in Font.h from RetainPtr<CFDictionaryRef> to RetainPtr<CFMutableDictionaryRef>, but that's more truthy anyway.

>> Source/WebCore/testing/cocoa/WebArchiveDumpSupport.mm:223
>> +    RetainPtr<CFMutableDictionaryRef> propertyList = adoptCF(checked_cf_cast<CFMutableDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &format, &error)));
> 
> For these WebArchive cases, I think that if we got an unexpected type that we would want to bail with an error message instead of crashing (inside a cast check). That said the checked casts are certainly better then previous behavior.

At best we could output the CFTypeID of the incorrectly typed object.  If it's a CoreFoundation type, then we might be able to give the name of the object type in the log output, but for CFTypes like DDResultRef (as a random example that probably would never happen here), I think the CFTypeID is assigned at runtime, so there's no way we could exhaustively map a CFTypeID to a string name at runtime.  So I'm not sure that the CFTypeID by itself would be all that useful in the crash output (again unless it's a native CoreFoundation type--although I didn't check if those had static CFTypeIDs or not).
Comment 36 David Kilzer (:ddkilzer) 2018-01-05 13:19:47 PST
(In reply to Joseph Pecoraro from comment #34)
> Comment on attachment 330394 [details]
> Patch v13
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=330394&action=review
> 
> Looks good to me. I didn't really understand the RetainPtr changes though so
> I'll let someone else review.

Internally, RetainPtr<> stores a pointer to the object it references using CFTypeRef:

    typedef CFTypeRef StorageType;

And CFTypeRef is defined as:

    typedef const CF_BRIDGED_TYPE(id) void * CFTypeRef;

The reason the const_cast<> is needed here is that some CF objects (like CFMutable*Ref types and most CF types defined outside of CoreFoundation.framework) are defined as non-const pointers (compare CFArrayRef to CFMutableArrayRef):

    typedef const struct CF_BRIDGED_TYPE(NSArray) __CFArray * CFArrayRef;
    typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableArray) __CFArray * CFMutableArrayRef;

    typedef struct DD_BRIDGED_TYPE(id) __DDResult * DDResultRef;

So when we request the "raw" pointer from a RetainPtr<> (using get() or leakRef()) with a template type that doesn't have a 'const' modifier, we need the const_cast<> to make sure the compiler doesn't emit a -Wcast-qual warning when casting from the internal 'const' (CFTypeRef) pointer to 'non-const' (template type) pointer.

The const_cast<> is not needed for CFTypes with 'const' modifiers, but it does no harm since casting from non-const back to const is okay.
Comment 37 David Kilzer (:ddkilzer) 2018-01-05 13:23:22 PST
Created attachment 330574 [details]
Patch v14
Comment 38 EWS Watchlist 2018-01-05 13:24:42 PST
Attachment 330574 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/cf/TypeCastsCF.h:70:  Please replace ASSERT_WITH_SECURITY_IMPLICATION() with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION().  [security/assertion] [5]
Total errors found: 1 in 22 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 39 Joseph Pecoraro 2018-01-05 13:50:44 PST
Comment on attachment 330574 [details]
Patch v14

r=me, thanks for the detailed explanation
Comment 40 WebKit Commit Bot 2018-01-05 15:34:43 PST
Comment on attachment 330574 [details]
Patch v14

Rejecting attachment 330574 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-01', 'land-attachment', '--force-clean', '--non-interactive', '--parent-command=commit-queue', 330574, '--port=mac']" exit_code: 2 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
.webkit.org/git/WebKit
   e552102..c1c0711  master     -> origin/master
Partial-rebuilding .git/svn/refs/remotes/origin/master/.rev_map.268f45cc-cd09-0410-ab3c-d52691b4dbfc ...
Currently at 226466 = e55210209101d2e7c86dddd6a26640e11db1ea9d
r226467 = c1c07115837487ce093672773264ad8605be5ef6
Done rebuilding .git/svn/refs/remotes/origin/master/.rev_map.268f45cc-cd09-0410-ab3c-d52691b4dbfc
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/origin/master.

Full output: http://webkit-queues.webkit.org/results/5947220
Comment 41 WebKit Commit Bot 2018-01-05 19:20:00 PST
Comment on attachment 330574 [details]
Patch v14

Clearing flags on attachment: 330574

Committed r226483: <https://trac.webkit.org/changeset/226483>
Comment 42 WebKit Commit Bot 2018-01-05 19:20:03 PST
All reviewed patches have been landed.  Closing bug.