summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-24 18:41:42 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-25 22:08:24 +0300
commitd49a520d19f28c613c68b574686b182a9c0621be (patch)
tree5b6943125fd364eaaaaa295b45100cdfc473dd93 /src/resources
parent14f55eb8c6e44763e70046b9661bd056280226a5 (diff)
downloadplus-d49a520d19f28c613c68b574686b182a9c0621be.tar.gz
plus-d49a520d19f28c613c68b574686b182a9c0621be.tar.bz2
plus-d49a520d19f28c613c68b574686b182a9c0621be.tar.xz
plus-d49a520d19f28c613c68b574686b182a9c0621be.zip
Add missing checks into resources directory.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/atlasitem.h4
-rw-r--r--src/resources/atlasmanager.cpp4
-rw-r--r--src/resources/atlasmanager.h4
-rw-r--r--src/resources/beingcommon.h4
-rw-r--r--src/resources/dye.cpp6
-rw-r--r--src/resources/dyepalette.cpp12
-rw-r--r--src/resources/dyepalette.h4
-rw-r--r--src/resources/imagehelper.cpp2
-rw-r--r--src/resources/iteminfo.h12
-rw-r--r--src/resources/mapreader.cpp26
-rw-r--r--src/resources/resourcemanager.cpp2
-rw-r--r--src/resources/resourcemanager.h4
-rw-r--r--src/resources/spritedef.cpp13
-rw-r--r--src/resources/subimage.cpp12
14 files changed, 78 insertions, 31 deletions
diff --git a/src/resources/atlasitem.h b/src/resources/atlasitem.h
index b404dac48..59485f691 100644
--- a/src/resources/atlasitem.h
+++ b/src/resources/atlasitem.h
@@ -34,8 +34,8 @@ struct AtlasItem final
name(),
x(0),
y(0),
- width(image0->mBounds.w),
- height(image0->mBounds.h)
+ width(image0 ? image0->mBounds.w : 0),
+ height(image0 ? image0->mBounds.h : 0)
{
}
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index f7afab0f6..23a1ec653 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -319,6 +319,8 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas)
void AtlasManager::injectToResources(const AtlasResource *const resource)
{
+ if (!resource)
+ return;
ResourceManager *const resman = ResourceManager::getInstance();
FOR_EACH (std::vector<TextureAtlas*>::const_iterator,
it, resource->atlases)
@@ -344,6 +346,8 @@ void AtlasManager::injectToResources(const AtlasResource *const resource)
void AtlasManager::moveToDeleted(AtlasResource *const resource)
{
+ if (!resource)
+ return;
ResourceManager *const resman = ResourceManager::getInstance();
FOR_EACH (std::vector<TextureAtlas*>::iterator, it, resource->atlases)
{
diff --git a/src/resources/atlasmanager.h b/src/resources/atlasmanager.h
index 91c269040..83a5ad7de 100644
--- a/src/resources/atlasmanager.h
+++ b/src/resources/atlasmanager.h
@@ -60,10 +60,10 @@ class AtlasManager final
int size);
static SDL_Surface *createSDLAtlas(TextureAtlas *const atlas)
- A_WARN_UNUSED;
+ A_WARN_UNUSED A_NONNULL(1);
- static void convertAtlas(TextureAtlas *const atlas);
+ static void convertAtlas(TextureAtlas *const atlas) A_NONNULL(1);
};
#endif // USE_OPENGL
diff --git a/src/resources/beingcommon.h b/src/resources/beingcommon.h
index 04e93a3cb..90bdf2b67 100644
--- a/src/resources/beingcommon.h
+++ b/src/resources/beingcommon.h
@@ -52,7 +52,7 @@ namespace BeingCommon
{
void readBasicAttributes(BeingInfo *const info,
XmlNodePtrConst node,
- const std::string &hoverCursor);
+ const std::string &hoverCursor) A_NONNULL(1);
void getIncludeFiles(const std::string &dir,
StringVect &list,
@@ -61,7 +61,7 @@ namespace BeingCommon
bool readObjectNodes(XmlNodePtrConst &spriteNode,
SpriteDisplay &display,
BeingInfo *const currentInfo,
- const std::string &dbName);
+ const std::string &dbName) A_NONNULL(3);
} // namespace BeingCommon
#endif // RESOURCES_BEINGCOMMON_H
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 34a1937a5..c7287ee8a 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -150,6 +150,9 @@ int Dye::getType() const
void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const
{
+ if (!pixels)
+ return;
+
#ifdef ENABLE_CILKPLUS
cilk_for (int ptr = 0; ptr < bufSize; ptr ++)
{
@@ -265,6 +268,9 @@ endlabel:{}
void Dye::normalOGLDye(uint32_t *restrict pixels, const int bufSize) const
{
+ if (!pixels)
+ return;
+
#ifdef ENABLE_CILKPLUS
cilk_for (int ptr = 0; ptr < bufSize; ptr ++)
{
diff --git a/src/resources/dyepalette.cpp b/src/resources/dyepalette.cpp
index 44049997a..895f9c03f 100644
--- a/src/resources/dyepalette.cpp
+++ b/src/resources/dyepalette.cpp
@@ -100,7 +100,7 @@ unsigned int DyePalette::hexDecode(const signed char c)
}
void DyePalette::getColor(const unsigned int intensity,
- unsigned int color[3]) const
+ unsigned int (&color)[3]) const
{
if (intensity == 0)
{
@@ -152,7 +152,7 @@ void DyePalette::getColor(const unsigned int intensity,
color[2] = ((255 - t) * b1 + t * b2) / 255;
}
-void DyePalette::getColor(double intensity, int color[3]) const
+void DyePalette::getColor(double intensity, int (&color)[3]) const
{
// Nothing to do here
if (mColors.empty())
@@ -202,7 +202,7 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
{
std::vector<DyeColor>::const_iterator it_end = mColors.end();
const size_t sz = mColors.size();
- if (!sz)
+ if (!sz || !pixels)
return;
if (sz % 2)
-- it_end;
@@ -310,7 +310,7 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels,
{
std::vector<DyeColor>::const_iterator it_end = mColors.end();
const size_t sz = mColors.size();
- if (!sz)
+ if (!sz || !pixels)
return;
if (sz % 2)
-- it_end;
@@ -401,7 +401,7 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
{
std::vector<DyeColor>::const_iterator it_end = mColors.end();
const size_t sz = mColors.size();
- if (!sz)
+ if (!sz || !pixels)
return;
if (sz % 2)
-- it_end;
@@ -496,7 +496,7 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels,
{
std::vector<DyeColor>::const_iterator it_end = mColors.end();
const size_t sz = mColors.size();
- if (!sz)
+ if (!sz || !pixels)
return;
if (sz % 2)
-- it_end;
diff --git a/src/resources/dyepalette.h b/src/resources/dyepalette.h
index 3132077fb..467ec0ac1 100644
--- a/src/resources/dyepalette.h
+++ b/src/resources/dyepalette.h
@@ -50,12 +50,12 @@ class DyePalette final
* implicitly black (0, 0, 0).
*/
void getColor(const unsigned int intensity,
- unsigned int color[3]) const;
+ unsigned int (&color)[3]) const;
/**
* Gets a pixel color depending on its intensity.
*/
- void getColor(double intensity, int color[3]) const;
+ void getColor(double intensity, int (&color)[3]) const;
/**
* replace colors for SDL for S dye.
diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp
index 20697cfd6..e49a738f2 100644
--- a/src/resources/imagehelper.cpp
+++ b/src/resources/imagehelper.cpp
@@ -163,6 +163,8 @@ SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage)
void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image)
{
+ if (!image)
+ return;
if (image->format)
{
const SDL_PixelFormat * const format = image->format;
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 4c8d90f8c..4d40390d9 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -201,11 +201,6 @@ class ItemInfo final
void setDrawPriority(const int direction, const int n);
- static void setSpriteOrder(int *const ptr,
- const int direction,
- const int n,
- const int def = -1);
-
const std::map<int, int> &getTags() const A_WARN_UNUSED
{ return mTags; }
@@ -280,7 +275,12 @@ class ItemInfo final
int mDrawAfter[10];
int mDrawPriority[10];
- protected:
+ private:
+ static void setSpriteOrder(int *const ptr,
+ const int direction,
+ const int n,
+ const int def = -1) A_NONNULL(1);
+
SpriteDisplay mDisplay; /**< Display info (like icon) */
std::string mName;
std::string mDescription; /**< Short description. */
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 825be9a25..414a19d24 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -491,10 +491,19 @@ void MapReader::readProperties(const XmlNodePtrConst node,
BLOCK_END("MapReader::readProperties")
}
-inline static void setTile(Map *const map, MapLayer *const layer,
+inline static void setTile(Map *const map,
+ MapLayer *const layer,
const MapLayer::Type &layerType,
MapHeights *const heights,
- const int x, const int y, const int gid)
+ const int x, const int y,
+ const int gid) A_NONNULL(1, 2, 4);
+
+inline static void setTile(Map *const map,
+ MapLayer *const layer,
+ const MapLayer::Type &layerType,
+ MapHeights *const heights,
+ const int x, const int y,
+ const int gid)
{
const Tileset * const set = map->getTilesetWithGid(gid);
switch (layerType)
@@ -588,6 +597,9 @@ bool MapReader::readBase64Layer(const XmlNodePtrConst childNode,
int &restrict x, int &restrict y,
const int w, const int h)
{
+ if (!map || !layer || !childNode)
+ return false;
+
if (!compression.empty() && compression != "gzip"
&& compression != "zlib")
{
@@ -690,6 +702,9 @@ bool MapReader::readCsvLayer(const XmlNodePtrConst childNode,
int &restrict x, int &restrict y,
const int w, const int h)
{
+ if (!map || !layer || !childNode)
+ return false;
+
XmlNodePtrConst dataChild = childNode->xmlChildrenNode;
if (!dataChild)
return true;
@@ -733,6 +748,9 @@ bool MapReader::readCsvLayer(const XmlNodePtrConst childNode,
void MapReader::readLayer(const XmlNodePtr node, Map *const map)
{
+ if (!map || !node)
+ return;
+
// Layers are not necessarily the same size as the map
const int w = XML::getProperty(node, "width", map->getWidth());
const int h = XML::getProperty(node, "height", map->getHeight());
@@ -878,7 +896,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node,
Map *const map)
{
BLOCK_START("MapReader::readTileset")
- if (!map)
+ if (!map || !node)
{
BLOCK_END("MapReader::readTileset")
return nullptr;
@@ -1072,6 +1090,8 @@ Map *MapReader::createEmptyMap(const std::string &restrict filename,
void MapReader::updateMusic(Map *const map)
{
+ if (!map)
+ return;
std::string name = map->getProperty("shortName");
const size_t p = name.rfind(".");
if (p != std::string::npos)
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 9985ec67d..9d1f9de1e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -260,6 +260,8 @@ bool ResourceManager::cleanOrphans(const bool always)
void ResourceManager::logResource(const Resource *const res)
{
+ if (!res)
+ return;
#ifdef USE_OPENGL
const Image *const image = dynamic_cast<const Image *const>(res);
if (image)
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index c98d7957f..afe158d78 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -198,8 +198,6 @@ class ResourceManager final
void decRefDelete(Resource *const res);
- static void logResource(const Resource *const res);
-
/**
* Move resource to deleted resources list.
*/
@@ -262,6 +260,8 @@ class ResourceManager final
*/
static void cleanUp(Resource *const resource);
+ static void logResource(const Resource *const res);
+
static ResourceManager *instance;
std::set<SDL_Surface*> deletedSurfaces;
Resources mResources;
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 9dae7289e..20d0537d1 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -185,10 +185,16 @@ void SpriteDef::substituteActions()
substituteAction(SpriteAction::DEADRIDE, SpriteAction::DEAD);
}
-void SpriteDef::loadSprite(const XmlNodePtr spriteNode, const int variant,
+void SpriteDef::loadSprite(const XmlNodePtr spriteNode,
+ const int variant,
const std::string &palettes)
{
BLOCK_START("SpriteDef::loadSprite")
+ if (!spriteNode)
+ {
+ BLOCK_END("SpriteDef::loadSprite")
+ return;
+ }
// Get the variant
const int variantCount = XML::getProperty(spriteNode, "variants", 0);
int variant_offset = 0;
@@ -243,6 +249,9 @@ void SpriteDef::loadImageSet(const XmlNodePtr node,
void SpriteDef::loadAction(const XmlNodePtr node,
const int variant_offset)
{
+ if (!node)
+ return;
+
const std::string actionName = XML::getProperty(node, "name", "");
const std::string imageSetName = XML::getProperty(node, "imageset", "");
const unsigned hp = XML::getProperty(node, "hp", 100);
@@ -288,7 +297,7 @@ void SpriteDef::loadAnimation(const XmlNodePtr animationNode,
const ImageSet *const imageSet,
const int variant_offset) const
{
- if (!action || !imageSet)
+ if (!action || !imageSet || !animationNode)
return;
const std::string directionName =
diff --git a/src/resources/subimage.cpp b/src/resources/subimage.cpp
index 9ab4a55fe..0d5cf8c8a 100644
--- a/src/resources/subimage.cpp
+++ b/src/resources/subimage.cpp
@@ -29,7 +29,8 @@
#include "debug.h"
#ifdef USE_SDL2
-SubImage::SubImage(Image *const parent, SDL_Texture *const image,
+SubImage::SubImage(Image *const parent,
+ SDL_Texture *const image,
const int x, const int y,
const int width, const int height) :
Image(image, width, height),
@@ -81,7 +82,8 @@ SubImage::SubImage(Image *const parent, SDL_Texture *const image,
}
#endif
-SubImage::SubImage(Image *const parent, SDL_Surface *const image,
+SubImage::SubImage(Image *const parent,
+ SDL_Surface *const image,
const int x, const int y,
const int width, const int height) :
Image(image, false),
@@ -134,8 +136,10 @@ SubImage::SubImage(Image *const parent, SDL_Surface *const image,
}
#ifdef USE_OPENGL
-SubImage::SubImage(Image *const parent, const GLuint image,
- const int x, const int y, const int width, const int height,
+SubImage::SubImage(Image *const parent,
+ const GLuint image,
+ const int x, const int y,
+ const int width, const int height,
const int texWidth, const int texHeight) :
Image(image, width, height, texWidth, texHeight),
mInternalBounds(),