diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-03-21 05:18:35 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-03-21 05:22:21 -0400 |
commit | 5fefc4bbf6380960f11f0b125fc51b6efdc19e2e (patch) | |
tree | abf9468aa779480ed3b116a298cda5f9a5cee38c /src/util/serialize.cpp | |
parent | 0dc1aec50940140e28f434c524296e284e73d623 (diff) | |
download | minetest-5fefc4bbf6380960f11f0b125fc51b6efdc19e2e.tar.gz minetest-5fefc4bbf6380960f11f0b125fc51b6efdc19e2e.tar.bz2 minetest-5fefc4bbf6380960f11f0b125fc51b6efdc19e2e.zip |
Fix serializing of signed numbers in serializeStructToString
Diffstat (limited to 'src/util/serialize.cpp')
-rw-r--r-- | src/util/serialize.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp index f05cfcc93..8779ee634 100644 --- a/src/util/serialize.cpp +++ b/src/util/serialize.cpp @@ -385,6 +385,9 @@ fail: } +// Casts *buf to a signed or unsigned fixed-width integer of 'w' width +#define SIGN_CAST(w, buf) (is_unsigned ? *((u##w *) buf) : *((s##w *) buf)) + bool serializeStructToString(std::string *out, std::string format, void *value) { @@ -412,15 +415,15 @@ bool serializeStructToString(std::string *out, case 'i': if (width == 16) { bufpos += PADDING(bufpos, u16); - os << *((u16 *) bufpos); + os << SIGN_CAST(16, bufpos); bufpos += sizeof(u16); } else if (width == 32) { bufpos += PADDING(bufpos, u32); - os << *((u32 *) bufpos); + os << SIGN_CAST(32, bufpos); bufpos += sizeof(u32); } else if (width == 64) { bufpos += PADDING(bufpos, u64); - os << *((u64 *) bufpos); + os << SIGN_CAST(64, bufpos); bufpos += sizeof(u64); } break; @@ -474,3 +477,5 @@ bool serializeStructToString(std::string *out, return true; } + +#undef SIGN_CAST |