Bug 69877 - Make CachedResourceClientWalker templated and have it do checked casts.
Summary: Make CachedResourceClientWalker templated and have it do checked casts.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nate Chapin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-11 15:54 PDT by Nate Chapin
Modified: 2011-10-12 10:50 PDT (History)
4 users (show)

See Also:


Attachments
patch (20.37 KB, patch)
2011-10-11 15:56 PDT, Nate Chapin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Chapin 2011-10-11 15:54:35 PDT
Followup to https://bugs.webkit.org/show_bug.cgi?id=69790, which introduced a bunch of unchecked casts that rely on CachedResource subtypes and CachedResourceClient subtypes matching each other correctly.  As written, it will fail dangerously in the event of a programmer error.
Comment 1 Nate Chapin 2011-10-11 15:56:51 PDT
Created attachment 110597 [details]
patch
Comment 2 WebKit Review Bot 2011-10-11 17:11:37 PDT
Comment on attachment 110597 [details]
patch

Clearing flags on attachment: 110597

Committed r97199: <http://trac.webkit.org/changeset/97199>
Comment 3 WebKit Review Bot 2011-10-11 17:11:42 PDT
All reviewed patches have been landed.  Closing bug.
Comment 4 Antti Koivisto 2011-10-12 01:03:51 PDT
Comment on attachment 110597 [details]
patch

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

> Source/WebCore/loader/cache/CachedResourceClientWalker.h:54
> +            if (m_clientSet.contains(next) && (T::expectedType() == CachedResourceClient::expectedType() || next->type() == T::expectedType()))
> +                return static_cast<T*>(next);

What is the purpose of T::expectedType() == CachedResourceClient::expectedType()?

Could this assert the correct type instead?
Comment 5 Nate Chapin 2011-10-12 08:52:44 PDT
(In reply to comment #4)
> (From update of attachment 110597 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=110597&action=review
> 
> > Source/WebCore/loader/cache/CachedResourceClientWalker.h:54
> > +            if (m_clientSet.contains(next) && (T::expectedType() == CachedResourceClient::expectedType() || next->type() == T::expectedType()))
> > +                return static_cast<T*>(next);
> 
> What is the purpose of T::expectedType() == CachedResourceClient::expectedType()?
> 
> Could this assert the correct type instead?

The purpose is to handle the notifyFinished() callback correctly.  notifyFinished() is called for all CachedResourceClient types, and is templated with the base class rather than a subclass.

I suppose we could assert instead of just skipping clients of the wrong type.  I don't have a strong opinion.
Comment 6 Antti Koivisto 2011-10-12 10:50:02 PDT
I suspect that all cases where there are unexpected types on the list are bugs so assert would be the right choice.