Skip to content

Commit

Permalink
Use fixed-width format specifiers in serializeStructToString
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Mar 13, 2014
1 parent e4d1970 commit 875f132
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/util/serialize.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}
Expand Down

2 comments on commit 875f132

@cheapie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/cheapie/source/mt/minetest/src/util/serialize.cpp: In function ‘bool serializeStructToString(std::string*, std::string, void*)’:
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:420:27: error: expected ‘:’ before ‘PRIu16’
         is_unsigned ? "%" PRIu16 ", " : "%" PRIi16 ", ",
                           ^
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:420:27: error: ‘PRIu16’ was not declared in this scope
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:426:27: error: expected ‘:’ before ‘PRIu32’
         is_unsigned ? "%" PRIu32 ", " : "%" PRIi32 ", ",
                           ^
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:426:27: error: ‘PRIu32’ was not declared in this scope
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:432:27: error: expected ‘:’ before ‘PRIu64’
         is_unsigned ? "%" PRIu64 ", " : "%" PRIi64 ", ",
                           ^
/home/cheapie/source/mt/minetest/src/util/serialize.cpp:432:27: error: ‘PRIu64’ was not declared in this scope

@ShadowNinja
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted this commit. It should work now.

Please sign in to comment.