From 3363a19596a74e799fe35c3e0cf59f82fe56664f Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 15 Jul 2008 17:34:50 +0000 Subject: [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/trunk@6563 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/tags.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'crawl-ref/source/tags.cc') diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 8fa1ecd72e..d33daf981b 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) { -- cgit v1.2.3-54-g00ecf