mirror of
https://github.com/minetest/minetest.git
synced 2024-11-10 09:43:45 +01:00
Fix serializing of signed numbers in serializeStructToString
This commit is contained in:
parent
0dc1aec509
commit
5fefc4bbf6
@ -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,
|
bool serializeStructToString(std::string *out,
|
||||||
std::string format, void *value)
|
std::string format, void *value)
|
||||||
{
|
{
|
||||||
@ -412,15 +415,15 @@ bool serializeStructToString(std::string *out,
|
|||||||
case 'i':
|
case 'i':
|
||||||
if (width == 16) {
|
if (width == 16) {
|
||||||
bufpos += PADDING(bufpos, u16);
|
bufpos += PADDING(bufpos, u16);
|
||||||
os << *((u16 *) bufpos);
|
os << SIGN_CAST(16, bufpos);
|
||||||
bufpos += sizeof(u16);
|
bufpos += sizeof(u16);
|
||||||
} else if (width == 32) {
|
} else if (width == 32) {
|
||||||
bufpos += PADDING(bufpos, u32);
|
bufpos += PADDING(bufpos, u32);
|
||||||
os << *((u32 *) bufpos);
|
os << SIGN_CAST(32, bufpos);
|
||||||
bufpos += sizeof(u32);
|
bufpos += sizeof(u32);
|
||||||
} else if (width == 64) {
|
} else if (width == 64) {
|
||||||
bufpos += PADDING(bufpos, u64);
|
bufpos += PADDING(bufpos, u64);
|
||||||
os << *((u64 *) bufpos);
|
os << SIGN_CAST(64, bufpos);
|
||||||
bufpos += sizeof(u64);
|
bufpos += sizeof(u64);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -474,3 +477,5 @@ bool serializeStructToString(std::string *out,
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef SIGN_CAST
|
||||||
|
Loading…
Reference in New Issue
Block a user