summaryrefslogtreecommitdiff
path: root/src/utils
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/utils
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/utils')
-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
7 files changed, 33 insertions, 4 deletions
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))