Bug 157440 - Download progress on attachment elements sometimes exceeds element bounds
Summary: Download progress on attachment elements sometimes exceeds element bounds
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-06 17:39 PDT by Tim Horton
Modified: 2016-05-09 11:05 PDT (History)
6 users (show)

See Also:


Attachments
Patch (5.21 KB, patch)
2016-05-06 17:39 PDT, Tim Horton
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2016-05-06 17:39:21 PDT
Download progress on attachment elements sometimes exceeds element bounds
Comment 1 Tim Horton 2016-05-06 17:39:52 PDT
Created attachment 278298 [details]
Patch
Comment 2 Tim Horton 2016-05-06 17:43:07 PDT
<rdar://problem/25245440>
Comment 3 Darin Adler 2016-05-07 12:47:41 PDT
Comment on attachment 278298 [details]
Patch

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

> Source/WebCore/rendering/RenderThemeIOS.mm:1400
> +    void buildTitleLines(const RenderAttachment&, unsigned maximumLines);

Not a great argument name; its name is "maximum lines", but its value is a maximum number of lines or a count of lines. I find that slight cognitive dissonance a little annoying.

> Source/WebCore/rendering/RenderThemeIOS.mm:1449
> +    for (; lineIndex < std::min(maximumLines - 1, static_cast<unsigned>(lineCount)); ++lineIndex) {

Do have some guarantee that maximumLines is not zero?

Looks like this fails to compile on iOS because CFIndex is a signed type. So should probably write something more like this:

    std::min<CFIndex>(maximumLines - 1, lineCount)

Maybe also compute this limit outside the loop?

> Source/WebCore/rendering/RenderThemeIOS.mm:1451
>          CTLineRef line = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
>          addLine(line);

Better without the local variable I think.

> Source/WebCore/rendering/RenderThemeIOS.mm:1576
> +    BOOL forceSingleLineTitle = !action.isEmpty() || !subtitle.isEmpty() || hasProgress;

bool, not BOOL, please
Comment 4 Tim Horton 2016-05-09 09:52:34 PDT
(In reply to comment #3)
> Comment on attachment 278298 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=278298&action=review
> 
> > Source/WebCore/rendering/RenderThemeIOS.mm:1400
> > +    void buildTitleLines(const RenderAttachment&, unsigned maximumLines);
> 
> Not a great argument name; its name is "maximum lines", but its value is a
> maximum number of lines or a count of lines. I find that slight cognitive
> dissonance a little annoying.

Will rename!

> > Source/WebCore/rendering/RenderThemeIOS.mm:1449
> > +    for (; lineIndex < std::min(maximumLines - 1, static_cast<unsigned>(lineCount)); ++lineIndex) {
> 
> Do have some guarantee that maximumLines is not zero?

We do, at the callsite; it's only ever 1 or 2.

> Looks like this fails to compile on iOS because CFIndex is a signed type. So
> should probably write something more like this:
> 
>     std::min<CFIndex>(maximumLines - 1, lineCount)

OK.

> Maybe also compute this limit outside the loop?

Sure.

> > Source/WebCore/rendering/RenderThemeIOS.mm:1451
> >          CTLineRef line = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
> >          addLine(line);
> 
> Better without the local variable I think.
> 
> > Source/WebCore/rendering/RenderThemeIOS.mm:1576
> > +    BOOL forceSingleLineTitle = !action.isEmpty() || !subtitle.isEmpty() || hasProgress;
> 
> bool, not BOOL, please

I've been writing too much ObjC.
Comment 5 Tim Horton 2016-05-09 11:05:03 PDT
http://trac.webkit.org/changeset/200582