Closed Bug 1102586 Opened 7 years ago Closed 7 years ago

TraceLoggingGraph.cpp:107:61: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]


(Core :: JavaScript Engine, defect)

Not set





(Reporter: dholbert, Unassigned)


(Blocks 1 open bug)


Recently-introduced build warning, with up-to-date mozilla-inbound and gcc 4.8, on 64-bit Ubuntu 14.10:
js/src/vm/TraceLoggingGraph.cpp: In member function ‘uint32_t TraceLoggerGraphState::nextLoggerId()’:
js/src/vm/TraceLoggingGraph.cpp:107:61: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
                            numLoggers, numLoggers, numLoggers);

Looks like this file (TraceLoggingGraph.cpp) was only just created, in bug 1072903; hence, marking as blocking that bug.
Flags: needinfo?(hv1989)
I think we should probably be using "%z" here -- that's the format string for size_t.

(I recall that this wasn't standard C++ at some point, but according to a comment on [1], it's standard as of C++1x, and it's possible/likely that our C++1x requirements mean we can rely on %z being available. Plus, a MXR search shows that we already use it elsewhere [2] so we can probably rely on it.)

As far as I can tell from the Microsoft documentation and Visual Studio blog posts, Visual Studio 2013 still doesn't support %z (and I don't see it mentioned for the Visual Studio 2015 preview either). MSVC has '%I' instead:
(Sorry, I guess I meant "%zu" - u for unsigned, and z to indicate number-of-bytes-in-an-unsigned)

Well, we do seem to use %zu here at least:
>141     fprintf(stderr, "  file %s line %u offset %zu\n",
>142             script()->filename(), (unsigned) script()->lineno(),
>143             script()->pcToOffset(pc()));

...and pcToOffset there does indeed return size_t:
> 1066     size_t pcToOffset(const jsbytecode *pc) const {

RematerializedFrame.cpp doesn't seem to be excluded from our MSVC build, so I *think* MSVC is seeing & correctly-handling this format string there.

If we're worried though, we can always just use "%u" and static_cast<unsigned>(mySizeTValue).
Fixed in the patch queue. Thanks for reporting!
Closed: 7 years ago
Flags: needinfo?(hv1989)
Resolution: --- → FIXED
btw, MSVC because does not support %zu, the current approach for printf-ing size_t is to use MFBT's (nonstandard) PRIuSIZE format macro (from bug 1114724) in cross-platform code.
You need to log in before you can comment on or make changes to this bug.