summaryrefslogtreecommitdiffstats
path: root/src/shared/networkmessage.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-11-15 12:13:40 +0100
committerSimon Rettberg2016-11-15 12:13:40 +0100
commiteaebc23452813a8709d2bbb4d17fddb1b4f29d91 (patch)
tree956155fc2fc5b58498a4c494cc59b7adc68bc76a /src/shared/networkmessage.cpp
parent[server] Rewrite positioning logic of connection frames (diff)
downloadpvs2-eaebc23452813a8709d2bbb4d17fddb1b4f29d91.tar.gz
pvs2-eaebc23452813a8709d2bbb4d17fddb1b4f29d91.tar.xz
pvs2-eaebc23452813a8709d2bbb4d17fddb1b4f29d91.zip
Increase compiler warnings, fix a lot of those instances
- Add explicit casts - Comment out unused params - Remove ignored const return types
Diffstat (limited to 'src/shared/networkmessage.cpp')
-rw-r--r--src/shared/networkmessage.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/shared/networkmessage.cpp b/src/shared/networkmessage.cpp
index 61a29ea..64e02e7 100644
--- a/src/shared/networkmessage.cpp
+++ b/src/shared/networkmessage.cpp
@@ -13,41 +13,41 @@
#define MAX_MSG_LEN 60000
#define BYTE_SWAP4(x) \
- (((x & 0xFF000000) >> 24) | \
- ((x & 0x00FF0000) >> 8) | \
- ((x & 0x0000FF00) << 8) | \
- ((x & 0x000000FF) << 24))
+ ((((x) & 0xFF000000u) >> 24) | \
+ (((x) & 0x00FF0000u) >> 8) | \
+ (((x) & 0x0000FF00u) << 8) | \
+ (((x) & 0x000000FFu) << 24))
#define BYTE_SWAP2(x) \
- (((x & 0xFF00) >> 8) | \
- ((x & 0x00FF) << 8))
+ ((((x) & 0xFF00u) >> 8) | \
+ (((x) & 0x00FFu) << 8))
static quint16 _htons(quint16 x)
{
if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
return x;
- return BYTE_SWAP2(x);
+ return (quint16)BYTE_SWAP2(x);
}
static quint16 _ntohs(quint16 x)
{
if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
return x;
- return BYTE_SWAP2(x);
+ return (quint16)BYTE_SWAP2(x);
}
static quint32 _htonl(quint32 x)
{
if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
return x;
- return BYTE_SWAP4(x);
+ return (quint32)BYTE_SWAP4(x);
}
static quint32 _ntohl(quint32 x)
{
if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
return x;
- return BYTE_SWAP4(x);
+ return (quint32)BYTE_SWAP4(x);
}
/*
@@ -105,11 +105,11 @@ int NetworkMessage::readMessage(QAbstractSocket* socket)
while (_bufferSize > _bufferPos && socket->bytesAvailable() > 0) {
const qint64 ret = socket->read(_buffer + _bufferPos, _bufferSize - _bufferPos);
//qDebug() << "Read " << ret << " bytes";
- if (ret < 0) {
+ if (ret < 0 || ret > (_bufferSize - _bufferPos)) {
qDebug("Socket read failed (TCP), return code %d", (int)ret);
return NM_READ_FAILED;
}
- _bufferPos += ret;
+ _bufferPos += (quint32)ret;
//qDebug() << "Buffer has now " << _bufferPos << " of " << _bufferSize << " bytes";
}
if (_bufferSize == _bufferPos) {
@@ -200,9 +200,9 @@ bool NetworkMessage::writeMessage(QAbstractSocket * const socket)
const qint64 ret = socket->write(_buffer + _bufferPos, _bufferSize - _bufferPos);
if (ret == 0)
return true;
- if (ret < 0)
+ if (ret < 0 || ret > (_bufferSize - _bufferPos))
return false;
- _bufferPos += ret;
+ _bufferPos += (quint32)ret;
if (_bufferPos == _bufferSize) {
_bufferPos = 0;
_mode = 4;