summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net/download.cpp2
-rw-r--r--src/net/ea/inventoryhandler.cpp4
-rw-r--r--src/net/ea/loginhandler.cpp2
-rw-r--r--src/net/ea/network.cpp15
-rw-r--r--src/net/eathena/messagein.cpp8
-rw-r--r--src/net/eathena/messageout.cpp10
-rw-r--r--src/net/messagein.cpp20
-rw-r--r--src/net/messageout.cpp16
-rw-r--r--src/net/tmwa/messagein.cpp8
-rw-r--r--src/net/tmwa/messageout.cpp12
-rw-r--r--src/net/tmwa/playerhandler.cpp3
11 files changed, 58 insertions, 42 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index e1b5012fd..6d13be8bf 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -143,7 +143,7 @@ unsigned long Download::fadler32(FILE *const file)
rewind(file);
// Calculate Adler-32 checksum
- char *const buffer = new char[fileSize];
+ char *const buffer = new char[static_cast<size_t>(fileSize)];
const uInt read = static_cast<uInt>(fread(buffer, 1, fileSize, file));
unsigned long adler = adler32(0L, Z_NULL, 0);
adler = adler32(static_cast<uInt>(adler),
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 1daafc2d5..eacb98711 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -150,7 +150,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const
if (serverSlot < 0 || serverSlot > 13)
return 0;
- return EQUIP_CONVERT[serverSlot];
+ return static_cast<int>(EQUIP_CONVERT[serverSlot]);
}
int InventoryHandler::getSlot(const int eAthenaSlot)
@@ -168,7 +168,7 @@ int InventoryHandler::getSlot(const int eAthenaSlot)
mask <<= 1;
position++;
}
- return EQUIP_POINTS[position];
+ return static_cast<int>(EQUIP_POINTS[position]);
}
void InventoryHandler::processPlayerInventory(Net::MessageIn &msg,
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index d4cf0e59e..25ad6d916 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -78,7 +78,7 @@ void LoginHandler::loginAccount(LoginData *const loginData1) const
void LoginHandler::chooseServer(const unsigned int server,
const bool persistentIp) const
{
- if (server >= mWorlds.size() || !mWorlds[server])
+ if (static_cast<size_t>(server) >= mWorlds.size() || !mWorlds[server])
return;
ServerInfo *const charServer = getCharServer();
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 61a9499d0..c9360e9c9 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -176,7 +176,7 @@ void Network::skip(const int len)
if (mInSize >= mToSkip)
{
mInSize -= mToSkip;
- memmove(mInBuffer, mInBuffer + mToSkip, mInSize);
+ memmove(mInBuffer, mInBuffer + static_cast<size_t>(mToSkip), mInSize);
mToSkip = 0;
}
else
@@ -267,7 +267,8 @@ void Network::receive()
continue;
}
- const int ret = TcpNet::recv(mSocket, mInBuffer + mInSize,
+ const int ret = TcpNet::recv(mSocket,
+ mInBuffer + static_cast<size_t>(mInSize),
BUFFER_SIZE - mInSize);
if (!ret)
@@ -291,7 +292,9 @@ void Network::receive()
if (mInSize >= mToSkip)
{
mInSize -= mToSkip;
- memmove(mInBuffer, mInBuffer + mToSkip, mInSize);
+ memmove(mInBuffer,
+ mInBuffer + static_cast<size_t>(mToSkip),
+ mInSize);
mToSkip = 0;
}
else
@@ -332,9 +335,11 @@ void Network::setError(const std::string &error)
uint16_t Network::readWord(const int pos) const
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap16(*reinterpret_cast<uint16_t*>(mInBuffer + (pos)));
+ return SDL_Swap16(*reinterpret_cast<uint16_t*>(
+ mInBuffer + static_cast<size_t>(pos)));
#else
- return (*reinterpret_cast<uint16_t*>(mInBuffer + (pos)));
+ return (*reinterpret_cast<uint16_t*>(
+ mInBuffer + static_cast<size_t>(pos)));
#endif
}
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index e8e9049d9..6e542b698 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -53,10 +53,10 @@ int16_t MessageIn::readInt16()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + mPos, sizeof(int16_t));
+ memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + mPos, sizeof(int16_t));
+ memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
#endif
}
mPos += 2;
@@ -72,10 +72,10 @@ int32_t MessageIn::readInt32()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + mPos, sizeof(int32_t));
+ memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + mPos, sizeof(int32_t));
+ memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
#endif
}
mPos += 4;
diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp
index 07fd8093b..f797c6a95 100644
--- a/src/net/eathena/messageout.cpp
+++ b/src/net/eathena/messageout.cpp
@@ -43,7 +43,7 @@ MessageOut::MessageOut(const int16_t id):
mNetwork(EAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
+ mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
// +++ can be issue. call to virtual member
writeInt16(id);
@@ -61,9 +61,9 @@ void MessageOut::writeInt16(const int16_t value)
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + mPos, &swap, sizeof(int16_t));
+ memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + mPos, &value, sizeof(int16_t));
+ memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
#endif
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -75,9 +75,9 @@ void MessageOut::writeInt32(const int32_t value)
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + mPos, &swap, sizeof(int32_t));
+ memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + mPos, &value, sizeof(int32_t));
+ memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 121e1e58f..538ce6110 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -95,7 +95,7 @@ void MessageIn::readCoordinates(uint16_t &restrict x, uint16_t &restrict y,
uint8_t serverDir = 0;
if (mPos + 3 <= mLength)
{
- const char *const data = mData + mPos;
+ const char *const data = mData + static_cast<size_t>(mPos);
uint16_t temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
x = static_cast<uint16_t>(temp >> 6);
temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
@@ -127,7 +127,7 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
{
if (mPos + 5 <= mLength)
{
- const char *const data = mData + mPos;
+ const char *const data = mData + static_cast<size_t>(mPos);
uint16_t temp = MAKEWORD(data[3], data[2] & 0x000f);
dstX = static_cast<uint16_t>(temp >> 2);
@@ -179,12 +179,12 @@ std::string MessageIn::readString(int length)
}
// Read the string
- const char *const stringBeg = mData + mPos;
+ const char *const stringBeg = mData + static_cast<size_t>(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
const std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : length);
+ ? stringEnd - stringBeg : static_cast<size_t>(length));
mPos += length;
PacketCounters::incInBytes(length);
DEBUGLOG("readString: " + str);
@@ -205,11 +205,11 @@ std::string MessageIn::readRawString(int length)
}
// Read the string
- const char *const stringBeg = mData + mPos;
+ const char *const stringBeg = mData + static_cast<size_t>(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : length);
+ ? stringEnd - stringBeg : static_cast<size_t>(length));
mPos += length;
PacketCounters::incInBytes(length);
@@ -217,7 +217,8 @@ std::string MessageIn::readRawString(int length)
if (stringEnd)
{
- const size_t len2 = length - (stringEnd - stringBeg) - 1;
+ const size_t len2 = static_cast<size_t>(length)
+ - (stringEnd - stringBeg) - 1;
const char *const stringBeg2 = stringEnd + 1;
const char *const stringEnd2
= static_cast<const char *const>(memchr(stringBeg2, '\0', len2));
@@ -247,9 +248,10 @@ unsigned char *MessageIn::readBytes(int length)
return nullptr;
}
- unsigned char *const buf = new unsigned char[length + 2];
+ unsigned char *const buf
+ = new unsigned char[static_cast<size_t>(length + 2)];
- memcpy(buf, mData + mPos, length);
+ memcpy(buf, mData + static_cast<size_t>(mPos), length);
buf[length] = 0;
buf[length + 1] = 0;
mPos += length;
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index aeb409f14..1b78e2aee 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -71,11 +71,15 @@ void MessageOut::writeString(const std::string &string, int length)
expand(length);
// Write the actual string
- memcpy(mData + mPos, string.c_str(), stringLength);
+ memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
- memset(mData + mPos + stringLength, '\0', length - stringLength);
+ {
+ memset(mData + static_cast<size_t>(mPos + stringLength),
+ '\0',
+ length - stringLength);
+ }
mPos += length;
DEBUGLOG("writeString: " + string);
@@ -99,11 +103,15 @@ void MessageOut::writeStringNoLog(const std::string &string, int length)
expand(length);
// Write the actual string
- memcpy(mData + mPos, string.c_str(), stringLength);
+ memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
- memset(mData + mPos + stringLength, '\0', length - stringLength);
+ {
+ memset(mData + static_cast<size_t>(mPos + stringLength),
+ '\0',
+ length - stringLength);
+ }
mPos += length;
DEBUGLOG("writeString: ***");
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index c1a3032d0..0e855ef56 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -53,10 +53,10 @@ int16_t MessageIn::readInt16()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + mPos, sizeof(int16_t));
+ memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + mPos, sizeof(int16_t));
+ memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
#endif
}
mPos += 2;
@@ -72,10 +72,10 @@ int32_t MessageIn::readInt32()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + mPos, sizeof(int32_t));
+ memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + mPos, sizeof(int32_t));
+ memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
#endif
}
mPos += 4;
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index 9962e7975..b32dcb3e5 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -43,7 +43,7 @@ MessageOut::MessageOut(const int16_t id):
mNetwork(TmwAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
+ mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
// +++ can be issue. call to virtual member
writeInt16(id);
@@ -61,9 +61,9 @@ void MessageOut::writeInt16(const int16_t value)
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + mPos, &swap, sizeof(int16_t));
+ memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + mPos, &value, sizeof(int16_t));
+ memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
#endif
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -75,9 +75,9 @@ void MessageOut::writeInt32(const int32_t value)
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + mPos, &swap, sizeof(int32_t));
+ memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + mPos, &value, sizeof(int32_t));
+ memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
@@ -94,7 +94,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
DEBUGLOG(strprintf("writeCoordinates: %u,%u %u",
static_cast<unsigned>(x), static_cast<unsigned>(y),
static_cast<unsigned>(direction)));
- char *const data = mData + mPos;
+ char *const data = mData + static_cast<size_t>(mPos);
mNetwork->mOutSize += 3;
mPos += 3;
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index eea74a2a5..25a2e0cde 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -263,7 +263,8 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg)
if (serverVersion >= 4)
addVal = 3;
- while (buf - start + 1 < size && *(buf + addVal))
+ while (buf - start + 1 < size
+ && *(buf + static_cast<size_t>(addVal)))
{
unsigned char status = 255;
unsigned char ver = 0;