summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-25 22:31:50 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-25 23:31:02 +0300
commit7ee1d89a656c05b62fa3104b59504afed0037b69 (patch)
tree7a20e371ba1035fc43135f069407b51d81d15527 /src
parentd49a520d19f28c613c68b574686b182a9c0621be (diff)
downloadmanaverse-7ee1d89a656c05b62fa3104b59504afed0037b69.tar.gz
manaverse-7ee1d89a656c05b62fa3104b59504afed0037b69.tar.bz2
manaverse-7ee1d89a656c05b62fa3104b59504afed0037b69.tar.xz
manaverse-7ee1d89a656c05b62fa3104b59504afed0037b69.zip
Add missing checks into db directory.
Diffstat (limited to 'src')
-rw-r--r--src/resources/db/chardb.cpp6
-rw-r--r--src/resources/db/itemdb.cpp26
-rw-r--r--src/resources/db/mapdb.cpp4
-rw-r--r--src/utils/base64.cpp5
-rw-r--r--src/utils/glxhelper.cpp4
-rw-r--r--src/utils/mutex.h6
-rw-r--r--src/utils/physfsrwops.cpp11
-rw-r--r--src/utils/sdlpixel.h7
-rw-r--r--src/utils/stringutils.cpp2
-rw-r--r--src/utils/xml.cpp2
10 files changed, 56 insertions, 17 deletions
diff --git a/src/resources/db/chardb.cpp b/src/resources/db/chardb.cpp
index 9b6f24358..84cdd6327 100644
--- a/src/resources/db/chardb.cpp
+++ b/src/resources/db/chardb.cpp
@@ -102,8 +102,10 @@ void CharDB::loadMinMax(const XmlNodePtr node,
unsigned *restrict const min,
unsigned *restrict const max)
{
- *min = XML::getProperty(node, "min", 1);
- *max = XML::getProperty(node, "max", 10);
+ if (min)
+ *min = XML::getProperty(node, "min", 1);
+ if (max)
+ *max = XML::getProperty(node, "max", 10);
}
void CharDB::unload()
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index d1ec2d00f..2b1601c76 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -57,16 +57,16 @@ namespace
// Forward declarations
static void loadSpriteRef(ItemInfo *const itemInfo,
- const XmlNodePtr node);
+ const XmlNodePtr node) A_NONNULL(1);
static void loadSoundRef(ItemInfo *const itemInfo,
- const XmlNodePtr node);
-static void loadFloorSprite(SpriteDisplay *const display,
+ const XmlNodePtr node) A_NONNULL(1);
+static void loadFloorSprite(SpriteDisplay &display,
const XmlNodePtrConst node);
static void loadReplaceSprite(ItemInfo *const itemInfo,
- const XmlNodePtr replaceNode);
+ const XmlNodePtr replaceNode) A_NONNULL(1);
static void loadOrderSprite(ItemInfo *const itemInfo,
const XmlNodePtr node,
- const bool drawAfter);
+ const bool drawAfter) A_NONNULL(1);
static int parseSpriteName(const std::string &name);
static int parseDirectionName(const std::string &name);
@@ -453,7 +453,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
}
else if (xmlNameEqual(itemChild, "floor"))
{
- loadFloorSprite(&display, itemChild);
+ loadFloorSprite(display, itemChild);
}
else if (xmlNameEqual(itemChild, "replace"))
{
@@ -741,7 +741,7 @@ static int parseDirectionName(const std::string &name)
static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node)
{
const std::string gender = XML::getProperty(node, "gender", "unisex");
- if (!node->xmlChildrenNode)
+ if (!node || !node->xmlChildrenNode)
return;
const std::string filename = reinterpret_cast<const char*>(
@@ -758,7 +758,7 @@ static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node)
static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
{
- if (!node->xmlChildrenNode)
+ if (!node || !node->xmlChildrenNode)
return;
const std::string event = XML::getProperty(node, "event", "");
const std::string filename = reinterpret_cast<const char*>(
@@ -778,9 +778,11 @@ static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
}
}
-static void loadFloorSprite(SpriteDisplay *const display,
+static void loadFloorSprite(SpriteDisplay &display,
const XmlNodePtrConst floorNode)
{
+ if (!floorNode)
+ return;
for_each_xml_child_node(spriteNode, floorNode)
{
if (!spriteNode->xmlChildrenNode)
@@ -792,11 +794,11 @@ static void loadFloorSprite(SpriteDisplay *const display,
spriteNode->xmlChildrenNode->content);
currentSprite->variant
= XML::getProperty(spriteNode, "variant", 0);
- display->sprites.push_back(currentSprite);
+ display.sprites.push_back(currentSprite);
}
else if (xmlNameEqual(spriteNode, "particlefx"))
{
- display->particles.push_back(reinterpret_cast<const char*>(
+ display.particles.push_back(reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content));
}
}
@@ -805,6 +807,8 @@ static void loadFloorSprite(SpriteDisplay *const display,
static void loadReplaceSprite(ItemInfo *const itemInfo,
const XmlNodePtr replaceNode)
{
+ if (!replaceNode)
+ return;
const std::string removeSprite = XML::getProperty(
replaceNode, "sprite", "");
const int direction = parseDirectionName(XML::getProperty(
diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp
index 1bd63af2f..44c37771b 100644
--- a/src/resources/db/mapdb.cpp
+++ b/src/resources/db/mapdb.cpp
@@ -98,6 +98,8 @@ void MapDB::loadRemapXmlFile(const std::string &fileName)
void MapDB::readMap(XmlNodePtrConst node)
{
+ if (!node)
+ return;
const std::string map = XML::getProperty(node, "name", "");
if (map.empty())
return;
@@ -116,6 +118,8 @@ void MapDB::readMap(XmlNodePtrConst node)
void MapDB::readAtlas(XmlNodePtrConst node)
{
+ if (!node)
+ return;
const std::string atlas = XML::getProperty(node, "name", "");
if (atlas.empty())
return;
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 88fe8bf8f..7be63c090 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -42,8 +42,11 @@ static char base64_table[] =
static const char base64_pad = '=';
unsigned char *php3_base64_encode(const unsigned char *restrict const string,
- int length, int *restrict const ret_length)
+ int length,
+ int *restrict const ret_length)
{
+ if (!string)
+ return nullptr;
const unsigned char *current = string;
int i = 0;
unsigned char *const result = static_cast<unsigned char *>(
diff --git a/src/utils/glxhelper.cpp b/src/utils/glxhelper.cpp
index 40f2b6f9f..42ac8ccb5 100644
--- a/src/utils/glxhelper.cpp
+++ b/src/utils/glxhelper.cpp
@@ -48,6 +48,8 @@ void *GlxHelper::createContext(const unsigned long window,
XSync(display, false);
int (*handler)(Display *, XErrorEvent *) = XSetErrorHandler(ErrorHandler);
void *context = mglXGetCurrentContext();
+ if (!display)
+ return context;
if (isGLNull(mglXGetCurrentContext)
|| isGLNull(mglXCreateContextAttribs)
|| isGLNull(mglXChooseFBConfig))
@@ -124,6 +126,8 @@ bool GlxHelper::makeCurrent(const unsigned long window,
void *const display,
void *const context)
{
+ if (!display)
+ return false;
return mglXMakeCurrent(static_cast<Display*>(display), window, context);
}
diff --git a/src/utils/mutex.h b/src/utils/mutex.h
index 7fe3ad69c..d715dddad 100644
--- a/src/utils/mutex.h
+++ b/src/utils/mutex.h
@@ -90,12 +90,14 @@ inline void Mutex::unlock()
inline MutexLocker::MutexLocker(Mutex *const mutex) :
mMutex(mutex)
{
- mMutex->lock();
+ if (mMutex)
+ mMutex->lock();
}
inline MutexLocker::~MutexLocker()
{
- mMutex->unlock();
+ if (mMutex)
+ mMutex->unlock();
}
#endif // UTILS_MUTEX_H
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 10799b824..bc78d09cb 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -46,6 +46,8 @@ static int openedRWops = 0;
static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset,
const int whence)
{
+ if (!rw)
+ return -1;
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
PHYSFSINT pos = 0;
@@ -115,10 +117,13 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset,
return pos;
} /* physfsrwops_seek */
-static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw, void *ptr,
+static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw,
+ void *ptr,
const PHYSFSSIZE size,
const PHYSFSSIZE maxnum)
{
+ if (!rw)
+ return 0;
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_read(handle, ptr,
@@ -137,6 +142,8 @@ static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
const PHYSFSSIZE size,
const PHYSFSSIZE num)
{
+ if (!rw)
+ return 0;
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_write(handle, ptr,
@@ -150,6 +157,8 @@ static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
static int physfsrwops_close(SDL_RWops *const rw)
{
+ if (!rw)
+ return 0;
PHYSFS_file *const handle = static_cast<PHYSFS_file*>(
rw->hidden.unknown.data1);
if (!PHYSFS_close(handle))
diff --git a/src/utils/sdlpixel.h b/src/utils/sdlpixel.h
index 4fb7cd774..6e78c184b 100644
--- a/src/utils/sdlpixel.h
+++ b/src/utils/sdlpixel.h
@@ -145,6 +145,11 @@ inline unsigned int SDLAlpha32(const unsigned int src,
return (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
}
+inline unsigned short SDLAlpha16(const unsigned short src,
+ const unsigned short dst,
+ const unsigned char a,
+ const SDL_PixelFormat *const f) A_NONNULL(4);
+
/**
* Blends two 16 bit colors together.
*
@@ -178,6 +183,8 @@ inline unsigned short SDLAlpha16(const unsigned short src,
inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
const Color& color)
{
+ if (!surface)
+ return;
const int bpp = surface->format->BytesPerPixel;
SDL_LockSurface(surface);
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index b6251a378..3e067fe5c 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -294,6 +294,8 @@ const char* getSafeUtf8String(const std::string &text)
void getSafeUtf8String(std::string text, char *const buf)
{
+ if (!buf)
+ return;
const size_t sz = text.size();
const size_t size = sz + UTF8_MAX_SIZE;
if (size > 65500)
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index f2cbdb384..cb0cc56b8 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -245,6 +245,8 @@ namespace XML
XmlNodePtr findFirstChildByName(const XmlNodePtrConst parent,
const char *const name)
{
+ if (!parent)
+ return nullptr;
for_each_xml_child_node(child, parent)
{
if (xmlNameEqual(child, name))