Bug 54946 - FEConvolveMatrix.cpp: Work around Clang -Warray-bounds warning
Summary: FEConvolveMatrix.cpp: Work around Clang -Warray-bounds warning
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Hans Wennborg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-22 03:40 PST by Hans Wennborg
Modified: 2011-02-24 00:32 PST (History)
2 users (show)

See Also:


Attachments
Patch (3.72 KB, patch)
2011-02-22 03:48 PST, Hans Wennborg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Wennborg 2011-02-22 03:40:41 PST
FEConvolveMatrix.cpp: Work around Clang -Warray-bounds warning
Comment 1 Hans Wennborg 2011-02-22 03:48:08 PST
Created attachment 83294 [details]
Patch
Comment 2 Zoltan Herczeg 2011-02-22 04:23:13 PST
Never heard about your compiler, and the warning seems very strange. preserveAlphaValues is a template argument (it can be evaluated at compile time), isn't it? Anyway, I would put a '#if your compiler' around:

float totals[3 + (preserveAlphaValues ? 0 : 1)];

and set it to 4 all the times in your case. That one float does not require much stack, although unnecessery.
Comment 3 Hans Wennborg 2011-02-22 04:50:44 PST
(In reply to comment #2)
Thanks for your quick reply!

> Never heard about your compiler, and the warning seems very strange. preserveAlphaValues is a template argument (it can be evaluated at compile time), isn't it?

I know, I'm not entirely happy about the warning either.

The problem is that the warning doesn't care about control-flow. So when preserveAlphaValues=true, the instantiated code basically looks like

float totals[3];
if (false)
    totals[3] = ...; // <-- out-of-bounds warning here :(


> Anyway, I would put a '#if your compiler' around:
> 
> float totals[3 + (preserveAlphaValues ? 0 : 1)];
> 
> and set it to 4 all the times in your case. That one float does not require much stack, although unnecessery.

If it's possible, I'd prefer to find a way to do this without #ifdefs. Another solution would be something like this:

float totals[3 + (preserveAlphaValues ? 0 : 1)];
float *alphaTotals = &totals[2 + (preserveAlphaValues ? 0 : 1)];

if (!preserveAlphaValues)
    *alphaTotals = 0;

Do you think this would be acceptable?
Comment 4 Zoltan Herczeg 2011-02-22 06:50:37 PST
I am not a reviewer, so I can only give suggestions, but I would prefer to change the definition to:

float totals[4];

It is highly unlikely that extra float on the stack (4 byte) would cause any out-of-memory condition.
Comment 5 Hans Wennborg 2011-02-24 00:32:33 PST
Clang changed the warning, so marking this invalid. Sorry for the trouble.