summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-11 14:48:19 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-11 15:24:57 +0300
commitf1b82c1b06604c2c1eed750a6c980aa0b5355560 (patch)
tree3e524583691af0e5a17e5ee974439b4c6ea07ef4 /src/net
parent452f2489bf3225235797ea08ea0d466f80409a87 (diff)
downloadplus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.gz
plus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.bz2
plus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.xz
plus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.zip
First part of checks from Parasoft C++ Test.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/download.cpp17
-rw-r--r--src/net/messagein.cpp35
-rw-r--r--src/net/tmwa/beinghandler.cpp26
3 files changed, 53 insertions, 25 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 9dd90a1d1..fad1ec0b4 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -69,7 +69,8 @@ Download::Download(void *const ptr, const std::string &url,
mError(static_cast<char*>(calloc(CURL_ERROR_SIZE + 1, 1))),
mIgnoreError(ignoreError)
{
- mError[0] = 0;
+ if (mError)
+ mError[0] = 0;
mOptions.cancel = 0;
mOptions.memoryWrite = 0;
@@ -117,6 +118,8 @@ unsigned long Download::fadler32(FILE *const file)
// Calculate Adler-32 checksum
char *const buffer = static_cast<char*>(malloc(fileSize));
+ if (!buffer)
+ return 0;
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),
@@ -174,7 +177,8 @@ bool Download::start()
if (!mThread)
{
logger->log1(DOWNLOAD_ERROR_MESSAGE_THREAD);
- strcpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD);
+ if (mError)
+ strcpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD);
mUpdateFunction(mPtr, DOWNLOAD_STATUS_THREAD_ERROR, 0, 0);
if (!mIgnoreError)
return false;
@@ -290,9 +294,14 @@ int Download::downloadThread(void *ptr)
break;
case CURLE_COULDNT_CONNECT:
default:
- logger->log("curl error %d: %s host: %s",
- res, d->mError, d->mUrl.c_str());
+ {
+ if (d->mError)
+ {
+ logger->log("curl error %d: %s host: %s",
+ res, d->mError, d->mUrl.c_str());
+ }
break;
+ }
}
if (d->mOptions.cancel)
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 219ef8a2f..28a16cfbd 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -121,13 +121,21 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction)
serverDir = static_cast<uint8_t>(data[2] & 0x000f);
direction = fromServerDirection(serverDir);
+
+ DEBUGLOG(std::string("readCoordinates: ").append(toString(
+ static_cast<int>(x))).append(",").append(toString(
+ static_cast<int>(y))).append(",").append(toString(
+ static_cast<int>(serverDir))));
+ }
+ else
+ {
+ x = 0;
+ y = 0;
+ direction = 0;
+ logger->log("error: wrong readCoordinates packet");
}
mPos += 3;
PacketCounters::incInBytes(3);
- DEBUGLOG(std::string("readCoordinates: ").append(toString(
- static_cast<int>(x))).append(",").append(toString(
- static_cast<int>(y))).append(",").append(toString(
- static_cast<int>(serverDir))));
}
void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY,
@@ -146,13 +154,22 @@ void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY,
temp = MAKEWORD(data[2], data[1] & 0x003f);
srcY = static_cast<uint16_t>(temp >> 4);
+
+ DEBUGLOG(std::string("readCoordinatePair: ").append(toString(
+ static_cast<int>(srcX))).append(",").append(toString(
+ static_cast<int>(srcY))).append(" ").append(toString(
+ static_cast<int>(dstX))).append(",").append(toString(
+ static_cast<int>(dstY))));
+ }
+ else
+ {
+ srcX = 0;
+ srcY = 0;
+ dstX = 0;
+ dstY = 0;
+ logger->log("error: wrong readCoordinatePair packet");
}
mPos += 5;
- DEBUGLOG(std::string("readCoordinatePair: ").append(toString(
- static_cast<int>(srcX))).append(",").append(toString(
- static_cast<int>(srcY))).append(" ").append(toString(
- static_cast<int>(dstX))).append(",").append(toString(
- static_cast<int>(dstY))));
PacketCounters::incInBytes(5);
}
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index b127517ea..0f668d162 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -667,22 +667,24 @@ void BeingHandler::processBeingMove3(Net::MessageIn &msg) const
int16_t y = msg.readInt16();
const unsigned char *moves = msg.readBytes(len);
Path path;
- for (int f = 0; f < len; f ++)
+ if (moves)
{
- const unsigned char dir = moves[f];
- if (dir <= 7)
+ for (int f = 0; f < len; f ++)
{
- x += dirx[dir];
- y += diry[dir];
- path.push_back(Position(x, y));
- }
- else
- {
- logger->log("bad move packet: %d", dir);
+ const unsigned char dir = moves[f];
+ if (dir <= 7)
+ {
+ x += dirx[dir];
+ y += diry[dir];
+ path.push_back(Position(x, y));
+ }
+ else
+ {
+ logger->log("bad move packet: %d", dir);
+ }
}
+ delete [] moves;
}
-
- delete [] moves;
dstBeing->setPath(path);
}