Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix serializing of signed numbers in serializeStructToString
  • Loading branch information
ShadowNinja committed Mar 21, 2014
1 parent 0dc1aec commit 5fefc4b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util/serialize.cpp
Expand Up @@ -385,6 +385,9 @@ bool deSerializeStringToStruct(std::string valstr,
}


// 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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -474,3 +477,5 @@ bool serializeStructToString(std::string *out,

return true;
}

#undef SIGN_CAST

0 comments on commit 5fefc4b

Please sign in to comment.