Use fixed-width format specifiers in serializeStructToString
authorShadowNinja <shadowninja@minetest.net>
Thu, 13 Mar 2014 15:07:52 +0000 (11:07 -0400)
committerShadowNinja <shadowninja@minetest.net>
Thu, 13 Mar 2014 21:30:15 +0000 (17:30 -0400)
src/util/serialize.cpp

index 58f569fb7d0ae61b1e4a1ea88c633925df2315a2..170daa0f8038d99710f4f046777129fc1d28b87e 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "../exceptions.h"
 #include "../irrlichttypes.h"
 
+#include <inttypes.h>  // For PRIxN, cinttypes is C++11-only
 #include <sstream>
 #include <iomanip>
 #include <vector>
@@ -416,19 +417,19 @@ bool serializeStructToString(std::string *outstr,
                                if (width == 16) {
                                        bufpos += PADDING(bufpos, u16);
                                        nprinted = snprintf(sbuf + pos, sbuflen,
-                                                               is_unsigned ? "%u, " : "%d, ",
+                                                               is_unsigned ? "%" PRIu16 ", " : "%" PRIi16 ", ",
                                                                *((u16 *)bufpos));
                                        bufpos += sizeof(u16);
                                } else if (width == 32) {
                                        bufpos += PADDING(bufpos, u32);
                                        nprinted = snprintf(sbuf + pos, sbuflen,
-                                                               is_unsigned ? "%u, " : "%d, ",
+                                                               is_unsigned ? "%" PRIu32 ", " : "%" PRIi32 ", ",
                                                                *((u32 *)bufpos));
                                        bufpos += sizeof(u32);
                                } else if (width == 64) {
                                        bufpos += PADDING(bufpos, u64);
                                        nprinted = snprintf(sbuf + pos, sbuflen,
-                                                               is_unsigned ? "%llu, " : "%lli, ",
+                                                               is_unsigned ? "%" PRIu64 ", " : "%" PRIi64 ", ",
                                                                *((u64 *)bufpos));
                                        bufpos += sizeof(u64);
                                }