summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tags.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 17:34:50 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 17:34:50 +0000
commit3363a19596a74e799fe35c3e0cf59f82fe56664f (patch)
tree11cd9bbc9bb24107d7949d884eae21bc16925b30 /crawl-ref/source/tags.cc
parentf1b88777017f5ce54b3d22b09fa130751a3cd6e3 (diff)
downloadcrawl-ref-3363a19596a74e799fe35c3e0cf59f82fe56664f.tar.gz
crawl-ref-3363a19596a74e799fe35c3e0cf59f82fe56664f.zip
[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
Diffstat (limited to 'crawl-ref/source/tags.cc')
-rw-r--r--crawl-ref/source/tags.cc31
1 files changed, 16 insertions, 15 deletions
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 <cstdlib>
-#include <stdio.h>
-#include <string.h> // for memcpy
+#include <cstdio>
+#include <cstring> // for memcpy
#include <iterator>
#include <algorithm>
@@ -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<unsigned char>& buf, long data)
+void marshallLong(std::vector<unsigned char>& 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<unsigned char>& 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<typename T>
void marshall_as_long(writer& th, const T& t)
{