[Webkit-unassigned] [Bug 210456] New: dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>()

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Apr 13 14:34:45 PDT 2020


https://bugs.webkit.org/show_bug.cgi?id=210456

            Bug ID: 210456
           Summary: dictionaryValueOfType() in WebCoreArgumentCodersMac.mm
                    can be replaced with dynamic_cf_cast<>()
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: WebKit2
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: ddkilzer at webkit.org
                CC: aestes at apple.com, darin at apple.com

dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>(CFDictionaryGetValue()).

Currently dictionaryValueOfType() does this:

static CFTypeRef dictionaryValueOfType(CFDictionaryRef dictionary, CFStringRef key, CFTypeID type)
{
    CFTypeRef value = CFDictionaryGetValue(dictionary, key);
    if (value && CFGetTypeID(value) == type)
        return value;
    return nullptr;
}

And dynamic_cf_cast<>() does the same thing, but also adds a Debug assertion when the CFTypeIDs don't match:

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>(const_cast<CF_BRIDGED_TYPE(id) void*>(object));
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20200413/0bcaf43a/attachment.htm>


More information about the webkit-unassigned mailing list