Bug 44672

Summary: Fix warning in wtf/ByteArray.h
Product: WebKit Reporter: Csaba Osztrogonác <ossy>
Component: JavaScriptCoreAssignee: Csaba Osztrogonác <ossy>
Status: RESOLVED FIXED    
Severity: Normal CC: eric, loki, webkit.review.bot
Priority: P1    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: All   
Bug Depends on:    
Bug Blocks: 43191    
Attachments:
Description Flags
possibly fix
none
possibly hack to make MSVC and GCC happy
none
possibly fix for Win-EWS
none
proposed fix none

Csaba Osztrogonác
Reported 2010-08-26 02:39:37 PDT
gcc warning: ../../../JavaScriptCore/wtf/ByteArray.h: In member function ‘bool WebCore::FELighting::drawLighting(WebCore::CanvasPixelArray*, int, int)’: ../../../JavaScriptCore/wtf/ByteArray.h:66: warning: array subscript is above array bounds inlined getter functions used in drawLighting() cause this warning: ALWAYS_INLINE int upLeftPixelValue(); ALWAYS_INLINE int upPixelValue(); ALWAYS_INLINE int upRightPixelValue(); ALWAYS_INLINE int leftPixelValue(); ALWAYS_INLINE int centerPixelValue(); ALWAYS_INLINE int rightPixelValue(); ALWAYS_INLINE int downLeftPixelValue(); ALWAYS_INLINE int downPixelValue(); ALWAYS_INLINE int downRightPixelValue(); eg: ALWAYS_INLINE int FELighting::LightingData::upLeftPixelValue() { return static_cast<int>(pixels->get(offset - widthMultipliedByPixelSize - cPixelSize + cAlphaChannelOffset)); } How do you guarantee avoiding incorrect array subscripts? Zoltan, could you check and fix this bug, please? It would be the last step before enabling -Werror for QtWebKit x86-Linux build.
Attachments
possibly fix (365 bytes, patch)
2010-09-01 09:04 PDT, Csaba Osztrogonác
no flags
possibly hack to make MSVC and GCC happy (384 bytes, patch)
2010-09-01 17:06 PDT, Csaba Osztrogonác
no flags
possibly fix for Win-EWS (741 bytes, patch)
2010-09-02 03:35 PDT, Csaba Osztrogonác
no flags
proposed fix (1.40 KB, patch)
2010-09-02 06:28 PDT, Csaba Osztrogonác
no flags
Csaba Osztrogonác
Comment 1 2010-09-01 09:04:59 PDT
Created attachment 66218 [details] possibly fix possibly fix for EWS bots without changelog, please don't review
Gabor Loki
Comment 2 2010-09-01 10:03:42 PDT
> possibly fix for EWS bots without changelog, please don't review It is not a good solution. This will fail with msvc! See: http://msdn.microsoft.com/en-us/library/79wf64bc.aspx
Csaba Osztrogonác
Comment 3 2010-09-01 11:05:46 PDT
(In reply to comment #2) > > possibly fix for EWS bots without changelog, please don't review > > It is not a good solution. This will fail with msvc! > See: http://msdn.microsoft.com/en-us/library/79wf64bc.aspx It is an other idea, I try unsized array instead of zero sized. It should work now. I hope. :)
Gabor Loki
Comment 4 2010-09-01 12:19:47 PDT
Practically it is the same trick. MSVC 6.0 and MSVC 2003 say the same C4200 warning on it. I've tried it before. Only the MSVC 2010 allows something: http://msdn.microsoft.com/en-us/library/b6fae073.aspx So, I think it is not a good idea to use an unsized array with several compiler specific guards in order to avoid a bogus warning of GCC.
WebKit Review Bot
Comment 5 2010-09-01 15:47:18 PDT
Csaba Osztrogonác
Comment 6 2010-09-01 17:01:25 PDT
(In reply to comment #4) > Practically it is the same trick. > MSVC 6.0 and MSVC 2003 say the same C4200 warning on it. I've tried it before. > > Only the MSVC 2010 allows something: http://msdn.microsoft.com/en-us/library/b6fae073.aspx > > So, I think it is not a good idea to use an unsized array with several compiler specific guards in order to avoid a bogus warning of GCC. Unsized arrays are supported by all MSVC * Visual Studio 2010 * Visual Studio 2008 * Visual Studio 2005 * Visual Studio .NET 2003 But http://webkit.org/building/tools.html say that _only_ VS2005 is supported for building WebKit. Additionally the C99 standard [ISO/IEC 9899:1999] introduces flexible array members into the language, it should be supported by all compiler. Unfortunately I don't know what the problem is on Win EWS until https://bugs.webkit.org/show_bug.cgi?id=39199 is fixed.
Csaba Osztrogonác
Comment 7 2010-09-01 17:06:21 PDT
Created attachment 66300 [details] possibly hack to make MSVC and GCC happy Test for EWS bots, without changelog, please don't review.
Gabor Loki
Comment 8 2010-09-02 00:14:25 PDT
Ossy, I suggest you to use the following form (or a similar one) to avoid the warnings: +#if COMPILER(MSVC) +// These compilers do not support zero-sized array +#define DECLARATION_SIZE_OF_BYTEARRAY 0xffff +#else +#define DECLARATION_SIZE_OF_BYTEARRAY 0 +#endif ... -unsigned char m_data[sizeof(size_t)]; +unsigned char m_data[DECLARATION_SIZE_OF_BYTEARRAY];
Csaba Osztrogonác
Comment 9 2010-09-02 01:07:26 PDT
Comment on attachment 66300 [details] possibly hack to make MSVC and GCC happy Status bubbles are green, I'll add a changlog and upload again.
Csaba Osztrogonác
Comment 10 2010-09-02 03:35:57 PDT
Created attachment 66348 [details] possibly fix for Win-EWS warning C4200: nonstandard extension used : zero-sized array in struct/union Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array I think a possibly fix is defining private copy constructor and private operator= . MSVC can't generate them, I think nobody can generate correct copy constructor for this class. So we can implement them if we need it. I think we shouldn't copying a ByteArray object, so I prefer never used functions. Please don't review it, I would like to wait Windows EWS. If it will be green, I'll upload the patch with changelog for review.
Eric Seidel (no email)
Comment 11 2010-09-02 04:15:22 PDT
Csaba Osztrogonác
Comment 12 2010-09-02 04:19:20 PDT
Comment on attachment 66348 [details] possibly fix for Win-EWS I'm going to fix it on Mac.
Csaba Osztrogonác
Comment 13 2010-09-02 06:28:47 PDT
Created attachment 66364 [details] proposed fix First, I tried to use defined but not implemented copy constructor and operator=. And then I tried to implement them with ASSERT_NOT_REACHED(), but MSVC still warns. I propose to use maximal array size for MSVC and unsized array for other compilers. It won't cause memory problems, because you can create a ByteArray only with its create method, which absolutely ignores the sized of m_data array.
Csaba Osztrogonác
Comment 14 2010-09-03 06:57:24 PDT
Comment on attachment 66364 [details] proposed fix Clearing flags on attachment: 66364 Committed r66729: <http://trac.webkit.org/changeset/66729>
Csaba Osztrogonác
Comment 15 2010-09-03 06:57:34 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.