summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-02 05:11:50 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-02 05:11:50 +0300
commitf498d80c587033bffb9abedb2b0827ad8d4a2a32 (patch)
tree82da8928768b2159c199c2d033388a071f228582
parent1ba44aeb62414ea349e462b6d4fccbaac00be115 (diff)
downloadplus-f498d80c587033bffb9abedb2b0827ad8d4a2a32.tar.gz
plus-f498d80c587033bffb9abedb2b0827ad8d4a2a32.tar.bz2
plus-f498d80c587033bffb9abedb2b0827ad8d4a2a32.tar.xz
plus-f498d80c587033bffb9abedb2b0827ad8d4a2a32.zip
Add some checks after automatic checking.
-rw-r--r--src/actorsprite.cpp3
-rw-r--r--src/commandhandler.cpp6
-rw-r--r--src/configuration.h4
-rw-r--r--src/gui/charselectdialog.cpp2
-rw-r--r--src/gui/chatwindow.cpp3
-rw-r--r--src/gui/serverdialog.cpp2
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/setup_relations.cpp7
-rw-r--r--src/gui/setup_video.cpp4
-rw-r--r--src/gui/whoisonline.cpp3
-rw-r--r--src/gui/widgets/chattab.cpp14
-rw-r--r--src/gui/widgets/textbox.h3
-rw-r--r--src/guichan/gui.cpp2
-rw-r--r--src/guichan/include/guichan/sdl/sdlpixel.hpp6
-rw-r--r--src/guild.cpp7
-rw-r--r--src/localplayer.cpp3
-rw-r--r--src/map.cpp3
-rw-r--r--src/map.h3
-rw-r--r--src/net/tmwa/charserverhandler.cpp7
-rw-r--r--src/net/tmwa/playerhandler.cpp3
-rw-r--r--src/resources/soundeffect.h3
-rw-r--r--src/sound.cpp9
-rw-r--r--src/utils/stringutils.cpp3
23 files changed, 81 insertions, 21 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index c718c31f2..916b599f9 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -168,6 +168,9 @@ static bool effects_initialized = false;
static EffectDescription *getEffectDescription(XmlNodePtr node, int *id)
{
+ if (!id)
+ return nullptr;
+
EffectDescription *ed = new EffectDescription;
*id = atoi(XML::getProperty(node, "id", "-1").c_str());
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 7a588dc09..4022d8d58 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -665,6 +665,9 @@ void CommandHandler::handleNavigate(const std::string &args,
bool CommandHandler::parse2Int(const std::string &args, int *x, int *y)
{
+ if (!x || !y)
+ return false;
+
bool isValid = false;
const std::string::size_type pos = args.find(" ");
if (pos != std::string::npos)
@@ -1189,6 +1192,9 @@ void showRes(std::string str, ResourceManager::Resources *res);
void showRes(std::string str, ResourceManager::Resources *res)
{
+ if (!res)
+ return;
+
if (debugChatTab)
debugChatTab->chatLog(str + toString(res->size()));
logger->log(str + toString(res->size()));
diff --git a/src/configuration.h b/src/configuration.h
index 00479933e..122badfd5 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -253,10 +253,10 @@ class Configuration : public ConfigurationObject
void setSilent(const std::string &key, const std::string &value);
inline void setValue(const std::string &key, const char *value)
- { setValue(key, std::string(value)); }
+ { if (value) setValue(key, std::string(value)); }
inline void setSilent(const std::string &key, const char *value)
- { setSilent(key, std::string(value)); }
+ { if (value) setSilent(key, std::string(value)); }
inline void setValue(const std::string &key, float value)
{ setValue(key, toString(value)); }
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 638691bab..d2b74a632 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -386,7 +386,7 @@ bool CharSelectDialog::selectByName(const std::string &name,
Net::Character *character = mCharacterEntries[i]->getCharacter();
if (mCharacterEntries[i] && character)
{
- if (character->dummy->getName() == name)
+ if ( character->dummy && character->dummy->getName() == name)
{
if (mCharacterEntries[i])
mCharacterEntries[i]->requestFocus();
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 3d52e28f4..6831ad5b6 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -548,6 +548,9 @@ void ChatWindow::removeTab(ChatTab *tab)
void ChatWindow::addTab(ChatTab *tab)
{
+ if (!tab)
+ return;
+
mChatTabs->addTab(tab, tab->mScrollArea);
// Update UI
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index bdde4b96f..98d9bbfee 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -680,7 +680,7 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
int ServerDialog::downloadUpdate(void *ptr, DownloadStatus status,
size_t total, size_t remaining)
{
- if (status == DOWNLOAD_STATUS_CANCELLED)
+ if (!ptr || status == DOWNLOAD_STATUS_CANCELLED)
return -1;
ServerDialog *sd = reinterpret_cast<ServerDialog*>(ptr);
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index bac474950..3408fba33 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -75,7 +75,7 @@ Setup::Setup():
nullptr
};
int x = width;
- for (const char **curBtn = buttonNames; *curBtn; ++curBtn)
+ for (const char **curBtn = buttonNames; *curBtn; ++ curBtn)
{
Button *btn = new Button(gettext(*curBtn), *curBtn, this);
x -= btn->getWidth() + 5;
diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp
index 9ddef9e1a..571856a14 100644
--- a/src/gui/setup_relations.cpp
+++ b/src/gui/setup_relations.cpp
@@ -193,6 +193,8 @@ public:
std::string getPlayerAt(int index) const
{
+ if (index < 0 || index >= (signed)mPlayers->size())
+ return "";
return (*mPlayers)[index];
}
@@ -257,10 +259,7 @@ Setup_Relations::Setup_Relations():
mIgnoreActionChoicesBox = new DropDown(mIgnoreActionChoicesModel);
for (int i = 0; i < COLUMNS_NR; i++)
- {
- mPlayerTableTitleModel->set(0, i,
- new Label(gettext(table_titles[i])));
- }
+ mPlayerTableTitleModel->set(0, i, new Label(gettext(table_titles[i])));
mPlayerTitleTable->setLinewiseSelection(true);
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index d0a6ac257..48d489513 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -143,11 +143,11 @@ ModeListModel::ModeListModel()
}
else
{
- for (int i = 0; modes[i]; ++i)
+ for (int i = 0; modes[i]; ++ i)
{
const std::string modeString =
toString(static_cast<int>(modes[i]->w)) + "x"
- + toString(static_cast<int>(modes[i]->h));
+ + toString(static_cast<int>(modes[i]->h));
mVideoModes.push_back(modeString);
}
}
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index 7965221e4..205a1aae1 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -464,6 +464,9 @@ void WhoIsOnline::loadWebList()
size_t WhoIsOnline::memoryWrite(void *ptr, size_t size,
size_t nmemb, FILE *stream)
{
+ if (!stream)
+ return 0;
+
WhoIsOnline *wio = reinterpret_cast<WhoIsOnline *>(stream);
size_t totalMem = size * nmemb;
wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index aea367482..6d5dfc9dd 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -224,9 +224,17 @@ void ChatTab::chatLog(std::string line, Own own,
{
struct tm *timeInfo;
timeInfo = localtime(&t);
- line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
- timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
- tmp.text.c_str());
+ if (timeInfo)
+ {
+ line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
+ timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
+ tmp.text.c_str());
+ }
+ else
+ {
+ line = strprintf("%s %s%s", lineColor.c_str(),
+ tmp.nick.c_str(), tmp.text.c_str());
+ }
}
else
{
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index 6d2467b38..a052247c4 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -59,7 +59,8 @@ class TextBox : public gcn::TextBox
*/
inline void draw(gcn::Graphics *graphics)
{
- setForegroundColor(*mTextColor);
+ if (mTextColor)
+ setForegroundColor(*mTextColor);
gcn::TextBox::draw(graphics);
}
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index 3f5581424..1ade3f138 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -618,6 +618,7 @@ namespace gcn
{
Widget* widget = getWidgetAt(x, y);
+ //+++ possible nullpointer
if (mFocusHandler->getModalMouseInputFocused()
&& !widget->isModalMouseInputFocused())
{
@@ -631,6 +632,7 @@ namespace gcn
{
Widget* widget = mFocusHandler->getFocused();
+ //+++ possible nullpointer
while (widget->_getInternalFocusHandler()
&& widget->_getInternalFocusHandler()->getFocused())
{
diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp
index 675b10fcd..809ae4649 100644
--- a/src/guichan/include/guichan/sdl/sdlpixel.hpp
+++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp
@@ -60,6 +60,9 @@ namespace gcn
*/
inline const Color SDLgetPixel(SDL_Surface* surface, int x, int y)
{
+ if (!surface)
+ return Color(0, 0, 0, 0);
+
int bpp = surface->format->BytesPerPixel;
SDL_LockSurface(surface);
@@ -112,6 +115,9 @@ namespace gcn
inline void SDLputPixel(SDL_Surface* surface, int x, int y,
const Color& color)
{
+ if (!surface)
+ return;
+
int bpp = surface->format->BytesPerPixel;
SDL_LockSurface(surface);
diff --git a/src/guild.cpp b/src/guild.cpp
index e569bed65..238155d32 100644
--- a/src/guild.cpp
+++ b/src/guild.cpp
@@ -166,6 +166,8 @@ void Guild::removeMember(GuildMember *member)
itr_end = mMembers.end();
while (itr != itr_end)
{
+ if (!*itr)
+ continue;
if ((*itr)->mId == member->mId &&
(*itr)->mCharId == member->mCharId &&
(*itr)->getName() == member->getName())
@@ -175,7 +177,7 @@ void Guild::removeMember(GuildMember *member)
delete m;
return;
}
- ++itr;
+ ++ itr;
}
}
@@ -255,6 +257,9 @@ void Guild::setRights(short rights)
bool Guild::isMember(GuildMember *member) const
{
+ if (!member)
+ return false;
+
if (member->mGuild && member->mGuild != this)
return false;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index bd69d785f..27897a486 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1875,6 +1875,9 @@ void LocalPlayer::changeMode(unsigned *var, unsigned limit, const char *conf,
std::string (LocalPlayer::*func)(), unsigned def,
bool save)
{
+ if (!var)
+ return;
+
(*var) ++;
if (*var >= limit)
*var = def;
diff --git a/src/map.cpp b/src/map.cpp
index 2209cf997..ccb56561c 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1796,6 +1796,9 @@ MapItem *Map::findPortalXY(int x, int y)
for (it = mMapPortals.begin(), it_end = mMapPortals.end();
it != it_end; ++it)
{
+ if (!*it)
+ continue;
+
MapItem *item = *it;
if (item->mX == x && item->mY == y)
return item;
diff --git a/src/map.h b/src/map.h
index db8b092de..f336a7a72 100644
--- a/src/map.h
+++ b/src/map.h
@@ -152,7 +152,8 @@ class MapLayer: public ConfigListener
/**
* Set tile image with x + y * width already known.
*/
- void setTile(int index, Image *img) { mTiles[index] = img; }
+ void setTile(int index, Image *img)
+ { mTiles[index] = img; }
/**
* Draws this layer to the given graphics context. The coordinates are
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index 717df1284..1bee91144 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -364,8 +364,11 @@ void CharServerHandler::processCharLogin(Net::MessageIn &msg)
Net::Character *character = new Net::Character;
readPlayerData(msg, character, version);
mCharacters.push_back(character);
- logger->log("CharServer: Player: %s (%d)",
- character->dummy->getName().c_str(), character->slot);
+ if (character && character->dummy)
+ {
+ logger->log("CharServer: Player: %s (%d)",
+ character->dummy->getName().c_str(), character->slot);
+ }
}
Client::setState(STATE_CHAR_SELECT);
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 8747cf9c4..16e833ec9 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -229,6 +229,9 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg)
}
char *start = (char*)msg.readBytes(size);
+ if (!start)
+ return;
+
char *buf = start;
int addVal = 1;
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index 0df7f50d5..b8c9e8735 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -64,7 +64,8 @@ class SoundEffect : public Resource
/**
* Constructor.
*/
- SoundEffect(Mix_Chunk *soundEffect): mChunk(soundEffect)
+ SoundEffect(Mix_Chunk *soundEffect) :
+ mChunk(soundEffect)
{ }
Mix_Chunk *mChunk;
diff --git a/src/sound.cpp b/src/sound.cpp
index fb6958e25..913b55656 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -159,10 +159,17 @@ void Sound::info()
compiledVersion.major,
compiledVersion.minor,
compiledVersion.patch);
- logger->log("Sound::info() SDL_mixer: %i.%i.%i (linked)",
+ if (linkedVersion)
+ {
+ logger->log("Sound::info() SDL_mixer: %i.%i.%i (linked)",
linkedVersion->major,
linkedVersion->minor,
linkedVersion->patch);
+ }
+ else
+ {
+ logger->log1("Sound::info() SDL_mixer: unknown");
+ }
logger->log("Sound::info() Driver: %s", driver);
logger->log("Sound::info() Format: %s", format);
logger->log("Sound::info() Rate: %i", rate);
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 26accbc7d..a5c0c471b 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -554,6 +554,9 @@ std::string stringToHexPath(const std::string &str)
void deleteCharLeft(std::string &str, unsigned *pos)
{
+ if (!pos)
+ return;
+
while (*pos > 0)
{
(*pos)--;