Bug 43876 - REGRESSION(65135): format specifier warnings
Summary: REGRESSION(65135): format specifier warnings
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Csaba Osztrogonác
URL:
Keywords:
Depends on:
Blocks: 43191
  Show dependency treegraph
 
Reported: 2010-08-11 13:43 PDT by Csaba Osztrogonác
Modified: 2010-08-11 23:31 PDT (History)
2 users (show)

See Also:


Attachments
Patch (4.21 KB, patch)
2010-08-11 21:57 PDT, Fumitoshi Ukai
ap: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Csaba Osztrogonác 2010-08-11 13:43:01 PDT
warnings introduced in http://trac.webkit.org/changeset/65135:

32 bit release build:
../../../WebCore/websockets/WebSocketChannel.cpp:218: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 2 has type ‘size_t’

WebCore/websockets/WebSocketChannel.cpp:218:
m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, String::format("WebSocket frame (at %lu bytes) is too long.", newBufferSize), 0, m_handshake.clientOrigin());

32 bit debug build:
../../../WebCore/websockets/WebSocketChannel.cpp:205: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:205: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 4 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:218: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 2 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:258: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:280: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:288: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:294: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:294: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 4 has type ‘size_t’
../../../WebCore/websockets/WebSocketChannel.cpp:304: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 4 has type ‘size_t’

205: LOG(Network, "WebSocket buffer overflow (%lu+%lu)", m_bufferSize, len);
258: LOG(Network, "remaining in read buf %lu", m_bufferSize);
280: LOG(Network, "frame length overflow %lu", length);
288: LOG(Network, "frame length overflow %lu+%u", newLength, lengthMsgByte);
294: LOG(Network, "frame length integer wrap %lu->%lu", length, newLength);
304: LOG(Network, "frame buffer pointer wrap %p+%lu->%p", p, length, p + length);

The problem is that size_t is unsigned int (4 bytes) and 
not unsigned long int (8 bytes) on 32 bit systems.

Accordingly using %lu on 32 bit systems is incorrect, we have to
use %u or %lu depends on sizeof(size_t) instead of hard coded %lu.
Comment 1 Csaba Osztrogonác 2010-08-11 14:04:45 PDT
My first idea was replace %lu with %zu. 
But unfortunately Windows can't handle z modifier, but I.

We can fix it with #if guards, but in my opinion it is too ugly:

#if OS(WINDOWS)
   LOG( ... %Iu ... );
#else
   LOG( ... %zu ... );
#endif

Have you got any idea how could we fix it correctly?
Comment 2 Alexey Proskuryakov 2010-08-11 14:08:49 PDT
We could add a macro that expands to either %Iu or %zu, or we could cast the values to unsigned long.
Comment 3 Fumitoshi Ukai 2010-08-11 21:57:35 PDT
Created attachment 64187 [details]
Patch
Comment 4 Fumitoshi Ukai 2010-08-11 23:31:48 PDT
Committed r65219: <http://trac.webkit.org/changeset/65219>