summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-17 18:55:36 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-17 18:55:36 +0300
commit4ecdb004e81a459ea63ebd7127e1c945df43f9ce (patch)
treea8ece58a62724c4b088484e0b5c1f44fdbf2f7e1
parent334c1c50dfa57da0b91687e097db295a6a3b699b (diff)
downloadmanaplus-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.gz
manaplus-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.bz2
manaplus-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.tar.xz
manaplus-4ecdb004e81a459ea63ebd7127e1c945df43f9ce.zip
Fix issues detected by coverity.
-rw-r--r--src/fs/virtfs/direntry.h2
-rw-r--r--src/fs/virtfs/fsdir.cpp12
-rw-r--r--src/fs/virtfs/fsdirrwops.cpp11
-rw-r--r--src/fs/virtfs/fsentry.h2
-rw-r--r--src/fs/virtfs/zipentry.h2
-rw-r--r--src/fs/virtfs/zipreader.cpp6
-rw-r--r--src/gui/widgets/guitable.cpp5
-rw-r--r--src/gui/widgets/staticbrowserbox.cpp6
-rw-r--r--src/net/eathena/beingrecv.cpp4
-rw-r--r--src/net/net.cpp11
-rw-r--r--src/resources/inventory/complexinventory.cpp1
11 files changed, 47 insertions, 15 deletions
diff --git a/src/fs/virtfs/direntry.h b/src/fs/virtfs/direntry.h
index 41d9afc7c..18e700a6a 100644
--- a/src/fs/virtfs/direntry.h
+++ b/src/fs/virtfs/direntry.h
@@ -38,7 +38,7 @@ struct DirEntry final : public FsEntry
A_DELETE_COPY(DirEntry)
- ~DirEntry();
+ virtual ~DirEntry();
std::string userDir;
std::string rootSubDir;
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp
index 60fc9f977..be980ae65 100644
--- a/src/fs/virtfs/fsdir.cpp
+++ b/src/fs/virtfs/fsdir.cpp
@@ -377,6 +377,11 @@ namespace FsDir
}
#ifdef USE_FILE_FOPEN
const long pos = ftell(fd);
+ if (pos < 0)
+ {
+ reportAlways("FsDir::fileLength ftell error.");
+ return -1;
+ }
fseek(fd, 0, SEEK_END);
const long sz = ftell(fd);
fseek(fd, pos, SEEK_SET);
@@ -483,6 +488,13 @@ namespace FsDir
#ifdef USE_FILE_FOPEN
fseek(fd, 0, SEEK_END);
const long sz = ftell(fd);
+ if (sz < 0)
+ {
+ reportAlways("FsDir::fileLength ftell error.");
+ if (fd != FILEHDEFAULT)
+ FILECLOSE(fd);
+ return nullptr;
+ }
fseek(fd, 0, SEEK_SET);
fileSize = static_cast<int>(sz);
#else // USE_FILE_FOPEN
diff --git a/src/fs/virtfs/fsdirrwops.cpp b/src/fs/virtfs/fsdirrwops.cpp
index bef2534fb..b428ed333 100644
--- a/src/fs/virtfs/fsdirrwops.cpp
+++ b/src/fs/virtfs/fsdirrwops.cpp
@@ -25,6 +25,7 @@
#include "fs/virtfs/file.h"
#include "utils/cast.h"
+#include "utils/checkutils.h"
PRAGMA48(GCC diagnostic push)
PRAGMA48(GCC diagnostic ignored "-Wshadow")
@@ -86,6 +87,11 @@ namespace FsDir
int64_t len = 0;
#ifdef USE_FILE_FOPEN
const long curpos = ftell(fd);
+ if (curpos < 0)
+ {
+ reportAlways("FsDir::fileLength ftell error.");
+ return -1;
+ }
fseek(fd, 0, SEEK_END);
len = ftell(fd);
// fseek(fd, curpos, SEEK_SET);
@@ -105,7 +111,10 @@ namespace FsDir
if (len == -1)
{
#ifdef USE_FILE_FOPEN
- fseek(fd, curpos, SEEK_SET);
+ if (fseek(fd, curpos, SEEK_SET) < 0)
+ {
+ reportAlways("FsDir::fileLength fseek error.");
+ }
#endif // USE_FILE_FOPEN
logger->assertLog(
"VirtFs::rwops_seek:Can't find end of file.");
diff --git a/src/fs/virtfs/fsentry.h b/src/fs/virtfs/fsentry.h
index 81568adb7..09ca136b0 100644
--- a/src/fs/virtfs/fsentry.h
+++ b/src/fs/virtfs/fsentry.h
@@ -39,7 +39,7 @@ struct FsEntry notfinal
A_DELETE_COPY(FsEntry)
- ~FsEntry();
+ virtual ~FsEntry();
std::string root;
diff --git a/src/fs/virtfs/zipentry.h b/src/fs/virtfs/zipentry.h
index 3d8a21ced..eaf77889d 100644
--- a/src/fs/virtfs/zipentry.h
+++ b/src/fs/virtfs/zipentry.h
@@ -40,7 +40,7 @@ struct ZipEntry final : public FsEntry
A_DELETE_COPY(ZipEntry)
- ~ZipEntry();
+ virtual ~ZipEntry();
STD_VECTOR<ZipLocalHeader*> mHeaders;
STD_VECTOR<std::string> mDirs;
diff --git a/src/fs/virtfs/zipreader.cpp b/src/fs/virtfs/zipreader.cpp
index 017686e6b..7f3e48463 100644
--- a/src/fs/virtfs/zipreader.cpp
+++ b/src/fs/virtfs/zipreader.cpp
@@ -27,6 +27,7 @@
#include "utils/cast.h"
#include "utils/checkutils.h"
+#include "utils/delete2.h"
#include "utils/stringutils.h"
#include <zlib.h>
@@ -55,7 +56,7 @@ extern const char *dirSeparator;
{ \
reportAlways("Error reading " msg " in file %s", \
archiveName.c_str()); \
- delete header; \
+ delete2(header); \
delete [] buf; \
fclose(arcFile); \
return false; \
@@ -290,7 +291,10 @@ namespace ZipReader
const size_t outSize = header->uncompressSize;
uint8_t *restrict const out = new uint8_t[outSize];
if (outSize == 0)
+ {
+ delete [] in;
return out;
+ }
z_stream strm;
strm.zalloc = nullptr;
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 392755a20..9ff2075b1 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -593,6 +593,9 @@ void GuiTable::modelUpdated(const bool completed)
Widget *GuiTable::getWidgetAt(int x, int y)
{
+ if (mModel == nullptr)
+ return nullptr;
+
const int row = getRowForY(y);
const int column = getColumnForX(x);
@@ -602,7 +605,7 @@ Widget *GuiTable::getWidgetAt(int x, int y)
return mTopWidget;
}
- if ((mModel != nullptr) && row > -1 && column > -1)
+ if (row > -1 && column > -1)
{
Widget *const w = mModel->getElementAt(row, column);
if ((w != nullptr) && w->isFocusable())
diff --git a/src/gui/widgets/staticbrowserbox.cpp b/src/gui/widgets/staticbrowserbox.cpp
index 7be4b780e..5999b2adf 100644
--- a/src/gui/widgets/staticbrowserbox.cpp
+++ b/src/gui/widgets/staticbrowserbox.cpp
@@ -668,16 +668,12 @@ void StaticBrowserBox::updateHeight()
break;
std::string part = row.substr(start, len);
- int width = 0;
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
mLineParts.push_back(LinePart(CAST_S32(x),
CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], part.c_str(), bold));
+ int width = 0;
if (bold)
width = boldFont->getWidth(part);
else
diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp
index 435468fb6..c7c0c801c 100644
--- a/src/net/eathena/beingrecv.cpp
+++ b/src/net/eathena/beingrecv.cpp
@@ -703,7 +703,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
// because server don't send direction in move packet, we fixing it
uint8_t d = 0;
- if (srcX == dstX && srcY == dstY)
+ if (localPlayer != nullptr &&
+ srcX == dstX &&
+ srcY == dstY)
{ // if player did one step from invisible area to visible,
// move path is broken
int x2 = localPlayer->getTileX();
diff --git a/src/net/net.cpp b/src/net/net.cpp
index d6b6e2945..7f394bcc4 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -113,14 +113,18 @@ std::set<int> ignorePackets;
void connectToServer(const ServerInfo &server)
{
BLOCK_START("Net::connectToServer")
- if (networkType == server.type && (generalHandler != nullptr))
+ if (networkType == server.type &&
+ generalHandler != nullptr)
{
generalHandler->reload();
}
else
{
- if (networkType != ServerType::UNKNOWN && (generalHandler != nullptr))
+ if (networkType != ServerType::UNKNOWN &&
+ generalHandler != nullptr)
+ {
generalHandler->unload();
+ }
switch (server.type)
{
@@ -141,7 +145,8 @@ void connectToServer(const ServerInfo &server)
break;
}
- generalHandler->load();
+ if (generalHandler != nullptr)
+ generalHandler->load();
networkType = server.type;
}
diff --git a/src/resources/inventory/complexinventory.cpp b/src/resources/inventory/complexinventory.cpp
index 4d77cfdde..c6037fe38 100644
--- a/src/resources/inventory/complexinventory.cpp
+++ b/src/resources/inventory/complexinventory.cpp
@@ -161,6 +161,7 @@ void ComplexInventory::setItem(const int index,
equipped);
item2->setInvIndex(index);
item->addChild(item2, quantity);
+ delete item2;
mItems[index] = item;
mUsed ++;