Skip to content

Commit 875f132

Browse files
committedMar 13, 2014
Use fixed-width format specifiers in serializeStructToString
1 parent e4d1970 commit 875f132

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎src/util/serialize.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "../exceptions.h"
2525
#include "../irrlichttypes.h"
2626

27+
#include <inttypes.h> // For PRIxN, cinttypes is C++11-only
2728
#include <sstream>
2829
#include <iomanip>
2930
#include <vector>
@@ -416,19 +417,19 @@ bool serializeStructToString(std::string *outstr,
416417
if (width == 16) {
417418
bufpos += PADDING(bufpos, u16);
418419
nprinted = snprintf(sbuf + pos, sbuflen,
419-
is_unsigned ? "%u, " : "%d, ",
420+
is_unsigned ? "%" PRIu16 ", " : "%" PRIi16 ", ",
420421
*((u16 *)bufpos));
421422
bufpos += sizeof(u16);
422423
} else if (width == 32) {
423424
bufpos += PADDING(bufpos, u32);
424425
nprinted = snprintf(sbuf + pos, sbuflen,
425-
is_unsigned ? "%u, " : "%d, ",
426+
is_unsigned ? "%" PRIu32 ", " : "%" PRIi32 ", ",
426427
*((u32 *)bufpos));
427428
bufpos += sizeof(u32);
428429
} else if (width == 64) {
429430
bufpos += PADDING(bufpos, u64);
430431
nprinted = snprintf(sbuf + pos, sbuflen,
431-
is_unsigned ? "%llu, " : "%lli, ",
432+
is_unsigned ? "%" PRIu64 ", " : "%" PRIi64 ", ",
432433
*((u64 *)bufpos));
433434
bufpos += sizeof(u64);
434435
}

0 commit comments

Comments
 (0)