FEConvolveMatrix.cpp: Work around Clang -Warray-bounds warning
Created attachment 83294 [details] Patch
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.
(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?
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.
Clang changed the warning, so marking this invalid. Sorry for the trouble.