Closed Bug 695691 Opened 13 years ago Closed 13 years ago

GCC (correctly) warns against using %lu for size_t in scanf in nsMemoryReporterManager.cpp

Categories

(Toolkit :: about:memory, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla10

People

(Reporter: justin.lebar+bug, Unassigned)

Details

(Whiteboard: [inbound])

Attachments

(1 file)

size_t takes %zu.  Patch in a moment.
Attached patch Patch v1Splinter Review
Attachment #568053 - Flags: review?(nnethercote)
I looked into this a bit, and I don't think the 'z' length specifier is portable outside C99. While gnu-printf supports all the C99 flags, MinGW-w64 defaults to a MSVC-compatible version that includes none of them. This default can be changed by compiling with -D__USE_MINGW_ANSI_STDIO=1, but I presume that won't work for MSVC.

In addition, while the 'll' specifier is part of the C++11 standard (and is the only 64-bit length specifier that -pedantic doesn't reject), MinGW-w64 won't accept it even with -std=c++0x / -std=gnu++0x, unless -D__USE_MINGW_ANSI_STDIO=1 is also defined (I think that can be considered a bug, especially since MSVC has supported it since MSVC 2005).

So while you could technically use '%llu', that won't work without those compilation options.

With all that being said, if you just want something that works, the I64 specifier works in both MSVC and GCC (although -pedantic rejects it). Of course, then you still have to cast to uin64_t / unsigned __int64.

Reference:
http://www.mail-archive.com/mingw-w64-public@lists.sourceforge.net/msg00400.html
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=VS.100%29.aspx
This code is linux-only; it's reading /proc/self/stam.

If we really needed it to be portable, we could just make the variables of type long long.  But does it matter?
I guess not, so long as it compiles :)
Attachment #568053 - Flags: review?(nnethercote) → review+
https://hg.mozilla.org/mozilla-central/rev/ffbfb6a8d250
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla10
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: