summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 23:12:17 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 23:12:17 +0000
commit8d0205570b4dd7c1b647791e018ee4a05bc6250a (patch)
treeb35e2eeec3fbcaa67918a7a3ec41913d49213f37
parente7a22ae2c3721277180443d930d110edb7e180b8 (diff)
downloadcrawl-ref-8d0205570b4dd7c1b647791e018ee4a05bc6250a.tar.gz
crawl-ref-8d0205570b4dd7c1b647791e018ee4a05bc6250a.zip
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
-rw-r--r--crawl-ref/source/tags.cc31
-rw-r--r--crawl-ref/source/tags.h11
2 files changed, 22 insertions, 20 deletions
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 <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)
{
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 <stdio.h>
+#include <cstdio>
+#include <stdint.h>
#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);