summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am4
-rw-r--r--src/actormanager.cpp31
-rw-r--r--src/actormanager.h2
-rw-r--r--src/client.cpp83
-rw-r--r--src/game.cpp13
-rw-r--r--src/input/inputactionsortfunctor.h2
-rw-r--r--src/input/inputmanager.h9
-rw-r--r--src/listeners/charrenamelistener.cpp3
-rw-r--r--src/listeners/guitableactionlistener.cpp7
-rw-r--r--src/localconsts.h6
-rw-r--r--src/net/ipc.cpp4
-rw-r--r--src/resources/imagehelper.h4
-rw-r--r--src/resources/imagerect.h2
-rw-r--r--src/shortcutbase.h4
-rw-r--r--src/spellmanager.cpp2
-rw-r--r--src/touchmanager.h4
16 files changed, 117 insertions, 63 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 58c1c2cd4..c8c80bcd6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,8 +15,8 @@ manaplus_CXXFLAGS += -DENABLE_PORTABLE
endif
if ENABLE_CHECKPLUGIN
-dyecmd_CXXFLAGS += -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers
-manaplus_CXXFLAGS += -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers
+dyecmd_CXXFLAGS += -DENABLE_CHECKPLUGIN -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers
+manaplus_CXXFLAGS += -DENABLE_CHECKPLUGIN -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers
endif
if USE_OPENGL
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 155d844ce..c046201d1 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -264,19 +264,24 @@ Being *ActorManager::createBeing(const BeingId id,
|| type == ActorType::Npc)
{
being->updateFromCache();
- beingHandler->requestNameById(id);
+ if (beingHandler)
+ beingHandler->requestNameById(id);
if (localPlayer)
localPlayer->checkNewName(being);
}
else if (type == ActorType::Monster)
{
- if (serverFeatures->haveMonsterName())
+ if (serverFeatures && serverFeatures->haveMonsterName())
beingHandler->requestNameById(id);
}
else if (type == ActorType::Portal)
{
- if (serverFeatures->haveServerWarpNames())
+ if (beingHandler &&
+ serverFeatures &&
+ serverFeatures->haveServerWarpNames())
+ {
beingHandler->requestNameById(id);
+ }
}
if (type == ActorType::Player)
{
@@ -513,10 +518,13 @@ void ActorManager::findBeingsByPixel(std::vector<ActorSprite*> &beings,
ActorSprite *const actor = *it;
- if ((being && (being->isAlive()
- || (mTargetDeadPlayers && being->getType() == ActorType::Player))
- && (allPlayers == AllPlayers_true || being != localPlayer))
- || actor->getType() == ActorType::FloorItem)
+ if ((being &&
+ (being->isAlive() ||
+ (mTargetDeadPlayers &&
+ being->getType() == ActorType::Player)) &&
+ (allPlayers == AllPlayers_true ||
+ being != localPlayer)) ||
+ actor->getType() == ActorType::FloorItem)
{
if ((actor->getPixelX() - xtol <= x) &&
(actor->getPixelX() + xtol > x) &&
@@ -834,9 +842,6 @@ void ActorManager::logic()
FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors)
{
const ActorSprite *const actor = *it;
- if (!actor)
- continue;
-
const ActorTypeT &type = actor->getType();
if (type == ActorType::Player)
{
@@ -1855,7 +1860,7 @@ void ActorManager::updateBadges()
for_actors
{
ActorSprite *const actor = *it;
- if (actor && actor->getType() == ActorType::Player)
+ if (actor->getType() == ActorType::Player)
{
Being *const being = static_cast<Being*>(actor);
being->showBadges(showBadges);
@@ -1869,7 +1874,7 @@ void ActorManager::removeRoom(const int chatId)
for_actors
{
ActorSprite *const actor = *it;
- if (actor && actor->getType() == ActorType::Npc)
+ if (actor->getType() == ActorType::Npc)
{
Being *const being = static_cast<Being*>(actor);
const ChatObject *const chat = being->getChat();
@@ -1889,7 +1894,7 @@ void ActorManager::updateRoom(const ChatObject *const newChat)
for_actors
{
ActorSprite *const actor = *it;
- if (actor && actor->getType() == ActorType::Npc)
+ if (actor->getType() == ActorType::Npc)
{
Being *const being = static_cast<Being*>(actor);
ChatObject *const chat = being->getChat();
diff --git a/src/actormanager.h b/src/actormanager.h
index d9c85336b..270530f48 100644
--- a/src/actormanager.h
+++ b/src/actormanager.h
@@ -64,7 +64,7 @@ class ActorManager final: public ConfigListener
/**
* Sets the current player.
*/
- void setPlayer(LocalPlayer *const player);
+ void setPlayer(LocalPlayer *const player) A_NONNULL(2);
/**
* Create a Being and add it to the list of ActorSprites.
diff --git a/src/client.cpp b/src/client.cpp
index f1a6a2396..d0abd144b 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -701,8 +701,12 @@ int Client::testsExec()
void Client::stateConnectGame1()
{
- if (gameHandler->isConnected())
+ if (gameHandler &&
+ loginHandler &&
+ gameHandler->isConnected())
+ {
loginHandler->disconnect();
+ }
}
void Client::stateConnectServer1()
@@ -771,6 +775,7 @@ void Client::stateConnectServer1()
}
}
else if (mOldState != STATE_CHOOSE_SERVER &&
+ loginHandler &&
loginHandler->isConnected())
{
mState = STATE_PRE_LOGIN;
@@ -779,7 +784,7 @@ void Client::stateConnectServer1()
void Client::stateWorldSelect1()
{
- if (mOldState == STATE_UPDATE)
+ if (mOldState == STATE_UPDATE && loginHandler)
{
if (loginHandler->getWorlds().size() < 2)
mState = STATE_PRE_LOGIN;
@@ -829,7 +834,7 @@ void Client::stateGame1()
void Client::stateSwitchLogin1()
{
- if (mOldState == STATE_GAME)
+ if (mOldState == STATE_GAME && gameHandler)
gameHandler->disconnect();
}
@@ -932,8 +937,10 @@ int Client::gameExec()
Party::clearParties();
Guild::clearGuilds();
NpcDialog::clearDialogs();
- guildHandler->clear();
- partyHandler->clear();
+ if (guildHandler)
+ guildHandler->clear();
+ if (partyHandler)
+ partyHandler->clear();
if (chatLogger)
chatLogger->clear();
if (!settings.options.dataPath.empty())
@@ -945,7 +952,7 @@ int Client::gameExec()
}
else if (mOldState == STATE_CHAR_SELECT)
{
- if (mState != STATE_CHANGEPASSWORD)
+ if (mState != STATE_CHANGEPASSWORD && charServerHandler)
charServerHandler->clear();
}
@@ -1086,7 +1093,8 @@ int Client::gameExec()
// TRANSLATORS: connection dialog header
_("Logging in"),
STATE_SWITCH_SERVER);
- loginHandler->loginOrRegister(&loginData);
+ if (loginHandler)
+ loginHandler->loginOrRegister(&loginData);
BLOCK_END("Client::gameExec STATE_LOGIN_ATTEMPT")
break;
@@ -1095,6 +1103,11 @@ int Client::gameExec()
logger->log1("State: WORLD SELECT");
{
TranslationManager::loadCurrentLang();
+ if (!loginHandler)
+ {
+ BLOCK_END("Client::gameExec STATE_WORLD_SELECT")
+ break;
+ }
Worlds worlds = loginHandler->getWorlds();
if (worlds.empty())
@@ -1262,7 +1275,8 @@ int Client::gameExec()
// TRANSLATORS: connection dialog header
_("Requesting characters"),
STATE_SWITCH_SERVER);
- charServerHandler->requestCharacters();
+ if (charServerHandler)
+ charServerHandler->requestCharacters();
BLOCK_END("Client::gameExec STATE_GET_CHARACTERS")
break;
@@ -1301,7 +1315,8 @@ int Client::gameExec()
// TRANSLATORS: connection dialog header
_("Connecting to the game server"),
STATE_CHOOSE_SERVER);
- gameHandler->connect();
+ if (gameHandler)
+ gameHandler->connect();
BLOCK_END("Client::gameExec STATE_CONNECT_GAME")
break;
@@ -1312,7 +1327,8 @@ int Client::gameExec()
// TRANSLATORS: connection dialog header
_("Changing game servers"),
STATE_SWITCH_CHARACTER);
- gameHandler->connect();
+ if (gameHandler)
+ gameHandler->connect();
BLOCK_END("Client::gameExec STATE_CHANGE_MAP")
break;
@@ -1418,7 +1434,8 @@ int Client::gameExec()
case STATE_REGISTER_ATTEMPT:
BLOCK_START("Client::gameExec STATE_REGISTER_ATTEMPT")
logger->log("Username is %s", loginData.username.c_str());
- loginHandler->registerAccount(&loginData);
+ if (loginHandler)
+ loginHandler->registerAccount(&loginData);
BLOCK_END("Client::gameExec STATE_REGISTER_ATTEMPT")
break;
@@ -1435,8 +1452,11 @@ int Client::gameExec()
BLOCK_START("Client::gameExec "
"STATE_CHANGEPASSWORD_ATTEMPT")
logger->log1("State: CHANGE PASSWORD ATTEMPT");
- loginHandler->changePassword(loginData.password,
- loginData.newPassword);
+ if (loginHandler)
+ {
+ loginHandler->changePassword(loginData.password,
+ loginData.newPassword);
+ }
BLOCK_END("Client::gameExec STATE_CHANGEPASSWORD_ATTEMPT")
break;
@@ -1472,7 +1492,8 @@ int Client::gameExec()
case STATE_CHANGEEMAIL_ATTEMPT:
logger->log1("State: CHANGE EMAIL ATTEMPT");
- loginHandler->changeEmail(loginData.email);
+ if (loginHandler)
+ loginHandler->changeEmail(loginData.email);
break;
case STATE_CHANGEEMAIL_SUCCESS:
@@ -1501,13 +1522,17 @@ int Client::gameExec()
case STATE_UNREGISTER_ATTEMPT:
logger->log1("State: UNREGISTER ATTEMPT");
- loginHandler->unregisterAccount(
+ if (loginHandler)
+ {
+ loginHandler->unregisterAccount(
loginData.username, loginData.password);
+ }
break;
case STATE_UNREGISTER_SUCCESS:
logger->log1("State: UNREGISTER SUCCESS");
- loginHandler->disconnect();
+ if (loginHandler)
+ loginHandler->disconnect();
mCurrentDialog = DialogsManager::openErrorDialog(
// TRANSLATORS: unregister message header
@@ -1525,9 +1550,13 @@ int Client::gameExec()
BLOCK_START("Client::gameExec STATE_SWITCH_SERVER")
logger->log1("State: SWITCH SERVER");
- loginHandler->disconnect();
- gameHandler->disconnect();
- gameHandler->clear();
+ if (loginHandler)
+ loginHandler->disconnect();
+ if (gameHandler)
+ {
+ gameHandler->disconnect();
+ gameHandler->clear();
+ }
settings.serverName.clear();
serverConfig.write();
serverConfig.unload();
@@ -1542,10 +1571,15 @@ int Client::gameExec()
BLOCK_START("Client::gameExec STATE_SWITCH_LOGIN")
logger->log1("State: SWITCH LOGIN");
- loginHandler->logout();
- loginHandler->disconnect();
- gameHandler->disconnect();
- loginHandler->connect();
+ if (loginHandler)
+ {
+ loginHandler->logout();
+ loginHandler->disconnect();
+ }
+ if (gameHandler)
+ gameHandler->disconnect();
+ if (loginHandler)
+ loginHandler->connect();
mState = STATE_LOGIN;
BLOCK_END("Client::gameExec STATE_SWITCH_LOGIN")
@@ -1556,7 +1590,8 @@ int Client::gameExec()
logger->log1("State: SWITCH CHARACTER");
// Done with game
- gameHandler->disconnect();
+ if (gameHandler)
+ gameHandler->disconnect();
mState = STATE_GET_CHARACTERS;
BLOCK_END("Client::gameExec STATE_SWITCH_CHARACTER")
diff --git a/src/game.cpp b/src/game.cpp
index b5e492ee5..0d239fa3e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -153,12 +153,13 @@ static void initEngines()
#endif
crazyMoves = new CrazyMoves;
- particleEngine = new Particle();
+ particleEngine = new Particle;
particleEngine->setMap(nullptr);
particleEngine->setupEngine();
BeingInfo::init();
- gameHandler->initEngines();
+ if (gameHandler)
+ gameHandler->initEngines();
keyboard.update();
if (joystick)
@@ -195,7 +196,7 @@ static void createGuiWindows()
CREATEWIDGETV(inventoryWindow, InventoryWindow,
PlayerInfo::getInventory());
#ifdef EATHENA_SUPPORT
- if (serverFeatures->haveCart())
+ if (serverFeatures && serverFeatures->haveCart())
{
CREATEWIDGETV(cartWindow, InventoryWindow,
PlayerInfo::getCartInventory());
@@ -285,7 +286,8 @@ static void createGuiWindows()
if (localPlayer)
localPlayer->updateStatus();
- generalHandler->gameStarted();
+ if (generalHandler)
+ generalHandler->gameStarted();
}
/**
@@ -293,7 +295,8 @@ static void createGuiWindows()
*/
static void destroyGuiWindows()
{
- generalHandler->gameEnded();
+ if (generalHandler)
+ generalHandler->gameEnded();
if (whoIsOnline)
whoIsOnline->setAllowUpdate(false);
diff --git a/src/input/inputactionsortfunctor.h b/src/input/inputactionsortfunctor.h
index fbd9b79f3..6e4c47582 100644
--- a/src/input/inputactionsortfunctor.h
+++ b/src/input/inputactionsortfunctor.h
@@ -35,7 +35,7 @@ class InputActionSortFunctor final
>= keys[static_cast<size_t>(key2)].priority;
}
- const InputActionData *keys;
+ const InputActionData *keys A_NONNULLPOINTER;
};
#endif // INPUT_INPUTACTIONSORTFUNCTOR_H
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index c9d71a091..f8e09e664 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -95,7 +95,7 @@ class InputManager final
/**
* Set a reference to the key setup window.
*/
- void setSetupInput(Setup_Input *const setupInput)
+ void setSetupInput(Setup_Input *const setupInput) A_NONNULL(2)
{ mSetupInput = setupInput; }
/**
@@ -145,9 +145,10 @@ class InputManager final
static bool isActionActive0(const InputActionT index) A_WARN_UNUSED;
- Setup_Input *mSetupInput; /**< Reference to setup window */
-
- InputActionT mNewKeyIndex; /**< Index of new key to be assigned */
+ /** Reference to setup window */
+ Setup_Input *mSetupInput A_NONNULLPOINTER;
+ /** Index of new key to be assigned */
+ InputActionT mNewKeyIndex;
int mMask;
diff --git a/src/listeners/charrenamelistener.cpp b/src/listeners/charrenamelistener.cpp
index a170cb9f3..13d6f69f1 100644
--- a/src/listeners/charrenamelistener.cpp
+++ b/src/listeners/charrenamelistener.cpp
@@ -41,7 +41,8 @@ void CharRenameListener::action(const ActionEvent &event)
return;
if (mDialog)
{
- charServerHandler->renameCharacter(mId, mDialog->getMsg());
+ if (charServerHandler)
+ charServerHandler->renameCharacter(mId, mDialog->getMsg());
mDialog = nullptr;
}
}
diff --git a/src/listeners/guitableactionlistener.cpp b/src/listeners/guitableactionlistener.cpp
index d0a2b7a18..70ec49129 100644
--- a/src/listeners/guitableactionlistener.cpp
+++ b/src/listeners/guitableactionlistener.cpp
@@ -56,6 +56,9 @@ GuiTableActionListener::~GuiTableActionListener()
void GuiTableActionListener::action(const ActionEvent &actionEvent A_UNUSED)
{
- mTable->setSelected(mRow, mColumn);
- mTable->distributeActionEvent();
+ if (mTable)
+ {
+ mTable->setSelected(mRow, mColumn);
+ mTable->distributeActionEvent();
+ }
}
diff --git a/src/localconsts.h b/src/localconsts.h
index 560e5f152..628584a45 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -150,6 +150,12 @@
#define FOR_EACHP(type, iter, array) for (type iter = array->begin(), \
iter##_end = array->end(); iter != iter##_end; ++ iter)
+#ifdef ENABLE_CHECKPLUGIN
+#define A_NONNULLPOINTER __attribute__((nonnullpointer))
+#else
+#define A_NONNULLPOINTER
+#endif
+
#ifdef ENABLE_CHECKS
#define CHECKLISTENERS \
diff --git a/src/net/ipc.cpp b/src/net/ipc.cpp
index e4a70abc8..f82330d04 100644
--- a/src/net/ipc.cpp
+++ b/src/net/ipc.cpp
@@ -93,7 +93,7 @@ int IPC::acceptLoop(void *ptr)
const int max_length = 1024;
const TcpNet::SocketSet set = TcpNet::allocSocketSet(1);
TcpNet::addSocket(set, ipc1->mSocket);
- ipc->mListen = true;
+ ipc1->mListen = true;
while (ipc1->mListen)
{
TcpNet::checkSockets(set, 250);
@@ -141,7 +141,7 @@ int IPC::acceptLoop(void *ptr)
}
TcpNet::closeSocket(ipc1->mSocket);
ipc1->mSocket = nullptr;
- ipc->mThread = nullptr;
+ ipc1->mThread = nullptr;
return 0;
}
diff --git a/src/resources/imagehelper.h b/src/resources/imagehelper.h
index 5c33e8207..c2354b4f3 100644
--- a/src/resources/imagehelper.h
+++ b/src/resources/imagehelper.h
@@ -111,6 +111,6 @@ class ImageHelper notfinal
static RenderType mUseOpenGL;
};
-extern ImageHelper *imageHelper;
-extern ImageHelper *surfaceImageHelper;
+extern ImageHelper *imageHelper A_NONNULLPOINTER;
+extern ImageHelper *surfaceImageHelper A_NONNULLPOINTER;
#endif // RESOURCES_IMAGEHELPER_H
diff --git a/src/resources/imagerect.h b/src/resources/imagerect.h
index 5ecb3a342..7cc06b250 100644
--- a/src/resources/imagerect.h
+++ b/src/resources/imagerect.h
@@ -68,7 +68,7 @@ class ImageRect final
LOWER_RIGHT = 8
};
- Image *grid[9];
+ Image *grid[9] A_NONNULLPOINTER;
};
#endif // RESOURCES_IMAGERECT_H
diff --git a/src/shortcutbase.h b/src/shortcutbase.h
index edfa76200..e742b6b18 100644
--- a/src/shortcutbase.h
+++ b/src/shortcutbase.h
@@ -124,8 +124,8 @@ class ShortcutBase notfinal
void clear(const bool isSave = true);
private:
- int *mItems;
- unsigned char *mItemColors;
+ int *mItems A_NONNULLPOINTER;
+ unsigned char *mItemColors A_NONNULLPOINTER;
std::string mItemName;
std::string mColorName;
int mItemSelected;
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index 12ba4a422..bc14f7537 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -131,7 +131,7 @@ void SpellManager::invoke(const int spellId) const
if (!spell)
return;
- if (spell->getCommand() == "")
+ if (!playerHandler || spell->getCommand().empty())
return;
if (spell->getCommandType() == TEXT_COMMAND_TEXT
diff --git a/src/touchmanager.h b/src/touchmanager.h
index e044e625f..e3bb93798 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -174,9 +174,9 @@ class TouchManager final : public ConfigListener
private:
TouchItem *mKeyboard;
TouchItem *mPad;
- TouchItem *mButtons[buttonsCount];
+ TouchItem *mButtons[buttonsCount] A_NONNULLPOINTER;
TouchItemVector mObjects;
- ImageCollection *mVertexes;
+ ImageCollection *mVertexes A_NONNULLPOINTER;
bool mActions[actionsSize];
bool mRedraw;
bool mShowJoystick;