From 8d0205570b4dd7c1b647791e018ee4a05bc6250a Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 15 Jul 2008 23:12:17 +0000 Subject: trunk->0.3 backport: r6563 [2018522] Fixed Lua marker deserialisation bug caused by unmarshallLong not expecting 64-bit longs. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6571 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/tags.cc | 31 ++++++++++++++++--------------- crawl-ref/source/tags.h | 11 ++++++----- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index ea38dd05b1..8d23cdf877 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -52,8 +52,8 @@ */ #include -#include -#include // for memcpy +#include +#include // for memcpy #include #include @@ -243,15 +243,15 @@ void marshallShort(writer &th, short data) } // Unmarshall 2 byte short in network order. -short unmarshallShort(reader &th) +int16_t unmarshallShort(reader &th) { - short b1 = th.readByte(); - short b2 = th.readByte(); - short data = (b1 << 8) | (b2 & 0x00FF); + int16_t b1 = th.readByte(); + int16_t b2 = th.readByte(); + int16_t data = (b1 << 8) | (b2 & 0x00FF); return data; } -void marshallLong(std::vector& buf, long data) +void marshallLong(std::vector& buf, int32_t data) { buf.push_back((unsigned char) ((data & 0xFF000000) >> 24)); buf.push_back((unsigned char) ((data & 0x00FF0000) >> 16)); @@ -260,7 +260,7 @@ void marshallLong(std::vector& buf, long data) } // Marshall 4 byte int in network order. -void marshallLong(writer &th, long data) +void marshallLong(writer &th, int32_t data) { char b4 = (char) (data & 0x000000FF); char b3 = (char)((data & 0x0000FF00) >> 8); @@ -273,19 +273,20 @@ void marshallLong(writer &th, long data) th.writeByte(b4); } -// Unmarshall 4 byte int in network order. -long unmarshallLong(reader &th) +// Unmarshall 4 byte signed int in network order. +int32_t unmarshallLong(reader &th) { - long b1 = th.readByte(); - long b2 = th.readByte(); - long b3 = th.readByte(); - long b4 = th.readByte(); + int32_t b1 = th.readByte(); + int32_t b2 = th.readByte(); + int32_t b3 = th.readByte(); + int32_t b4 = th.readByte(); - long data = (b1 << 24) | ((b2 & 0x000000FF) << 16); + int32_t data = (b1 << 24) | ((b2 & 0x000000FF) << 16); data |= ((b3 & 0x000000FF) << 8) | (b4 & 0x000000FF); return data; } +// FIXME: Kill this abomination - it will break! template void marshall_as_long(writer& th, const T& t) { diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index dfe48b17e6..1c5cdc8e78 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -13,7 +13,8 @@ #ifndef TAGS_H #define TAGS_H -#include +#include +#include #include "externs.h" enum tag_type // used during save/load process to identify data blocks @@ -85,8 +86,8 @@ private: }; void marshallByte (writer &, char ); -void marshallShort (writer &, short ); -void marshallLong (writer &, long ); +void marshallShort (writer &, int16_t ); +void marshallLong (writer &, int32_t ); void marshallFloat (writer &, float ); void marshallBoolean (writer &, bool ); void marshallString (writer &, const std::string &, int maxSize = 0); @@ -116,8 +117,8 @@ private: }; char unmarshallByte (reader &); -short unmarshallShort (reader &); -long unmarshallLong (reader &); +int16_t unmarshallShort (reader &); +int32_t unmarshallLong (reader &); float unmarshallFloat (reader &); bool unmarshallBoolean (reader &); int unmarshallCString (reader &, char *data, int maxSize); -- cgit v1.2.3-54-g00ecf