Compiling Warnings I'd like to solve

Noupz

New Member
Joined
Jul 13, 2010
Messages
114
Best answers
0
Reaction score
0
I use Ubuntu 14.04 with tfs 0.4 rev3777

when i am compiling, these warnings comes to me:

Warning in chat.cpp
Code:
chat.cpp: In member function ‘ChatChannel* Chat::getChannel(Player*, uint16_t)’:
chat.cpp:1143:10: warning: converting ‘false’ to pointer type ‘ChatChannel*’ [-Wconversion-null]
   return false;
Part in the file: "i has changed the false to NULL, but i am not sure about that"
Code:
ChatChannel* Chat::getChannel(Player* player, uint16_t channelId)
{
   #ifdef __DEBUG_CHAT__
   std::clog << "Chat::getChannel - getChannel id " << channelId << std::endl;
   #endif
   if(!player || player->isRemoved())
       return false;

   if(channelId == CHANNEL_GUILD)
   {
       GuildChannelMap::iterator git = m_guildChannels.find(player->getGuildId());
       if(git != m_guildChannels.end())
           return git->second;

       return NULL;
   }

   if(channelId == CHANNEL_PARTY)
   {
       if(player->getParty())
       {
           PartyChannelMap::iterator it = m_partyChannels.find(player->getParty());
           if(it != m_partyChannels.end())
               return it->second;
       }

       return NULL;
   }

   NormalChannelMap::iterator nit = m_normalChannels.find(channelId);
   if(nit != m_normalChannels.end())
   {
       #ifdef __DEBUG_CHAT__
       std::clog << "Chat::getChannel - found normal channel" << std::endl;
       #endif
       ChatChannel* tmpChannel = nit->second;
       if(!tmpChannel || !tmpChannel->hasFlag(CHANNELFLAG_ENABLED) || player->getAccess() < tmpChannel->getAccess()
           || (!player->hasCustomFlag(PlayerCustomFlag_GamemasterPrivileges) && !tmpChannel->checkVocation(
           player->getVocationId())))
       {
           #ifdef __DEBUG_CHAT__
           std::clog << "Chat::getChannel - cannot access normal channel" << std::endl;
           #endif
           return NULL;
       }

       if(channelId == CHANNEL_RVR && !player->hasFlag(PlayerFlag_CanAnswerRuleViolations))
           return NULL;

       #ifdef __DEBUG_CHAT__
       std::clog << "Chat::getChannel - endpoint return" << std::endl;
       #endif
       return tmpChannel;
   }

   PrivateChannelMap::iterator pit = m_privateChannels.find(channelId);
   if(pit != m_privateChannels.end() && pit->second->isInvited(player))
       return pit->second;

   return NULL;
}
-------------------------------
Warning in game.cpp
Code:
game.cpp: In member function ‘Item* Game::findItemOfType(Cylinder*, uint16_t, bool, int32_t)’:
game.cpp:1742:10: warning: converting ‘false’ to pointer type ‘Item*’ [-Wconversion-null]
   return false;
Part in the file: "the same of chat.cpp, false to null, but i am still not sure"
Code:
Item* Game::findItemOfType(Cylinder* cylinder, uint16_t itemId,
   bool depthSearch /*= true*/, int32_t subType /*= -1*/)
{
   if(!cylinder)
       return false;

   std::list<Container*> listContainer;
   Container* tmpContainer = NULL;

   Thing* thing = NULL;
   Item* item = NULL;
   for(int32_t i = cylinder->__getFirstIndex(); i < cylinder->__getLastIndex();)
   {
       if((thing = cylinder->__getThing(i)) && (item = thing->getItem()))
       {
           if(item->getID() == itemId && (subType == -1 || subType == item->getSubType()))
               return item;
           else
           {
               ++i;
               if(depthSearch && (tmpContainer = item->getContainer()))
                   listContainer.push_back(tmpContainer);
           }
       }
       else
           ++i;
   }

   while(listContainer.size() > 0)
   {
       Container* container = listContainer.front();
       listContainer.pop_front();
       for(int32_t i = 0; i < (int32_t)container->size();)
       {
           Item* item = container->getItem(i);
           if(item->getID() == itemId && (subType == -1 || subType == item->getSubType()))
               return item;
           else
           {
               ++i;
               if((tmpContainer = item->getContainer()))
                   listContainer.push_back(tmpContainer);
           }
       }
   }

   return NULL;
}
-------------------------------
Warning in luascript.cpp
Code:
luascript.cpp: In static member function ‘static int32_t LuaInterface::luaGetTownTemplePosition(lua_State*)’:
luascript.cpp:9509:7: warning: variable ‘displayError’ set but not used [-Wunused-but-set-variable]
  bool displayError = true;
Part in the file
Code:
int32_t LuaInterface::luaGetTownTemplePosition(lua_State* L)
{
   //getTownTemplePosition(townId)
   bool displayError = true;
   if(lua_gettop(L) >= 2)
       displayError = popNumber(L);

   uint32_t townId = popNumber(L);
   if(Town* town = Towns::getInstance()->getTown(townId))
       pushPosition(L, town->getPosition(), 255);
   else
       lua_pushboolean(L, false);

   return 1;
}
-------------------------------
Warning in monster.cpp
Code:
monster.cpp: In member function ‘virtual void Monster::doAttacking(uint32_t)’:
monster.cpp:662:26: warning: variable ‘outOfRange’ set but not used [-Wunused-but-set-variable]
  bool updateLook = true, outOfRange = true;
Part in the file
Code:
void Monster::doAttacking(uint32_t interval)
{
   if(!attackedCreature || (isSummon() && attackedCreature == this))
       return;

   bool updateLook = true, outOfRange = true;
   resetTicks = interval;
   attackTicks += interval;

   const Position& myPos = getPosition();
   for(SpellList::iterator it = mType->spellAttackList.begin(); it != mType->spellAttackList.end(); ++it)
   {
       if(!attackedCreature || attackedCreature->isRemoved())
           break;

       const Position& targetPos = attackedCreature->getPosition();
       if(it->isMelee && isFleeing())
           continue;

       bool inRange = false;
       if(canUseSpell(myPos, targetPos, *it, interval, inRange))
       {
           if(it->chance >= (uint32_t)random_range(1, 100))
           {
               if(updateLook)
               {
                   updateLookDirection();
                   updateLook = false;
               }

               double multiplier;
               if(maxCombatValue > 0) //defense
                   multiplier = g_config.getDouble(ConfigManager::RATE_MONSTER_DEFENSE);
               else //attack
                   multiplier = g_config.getDouble(ConfigManager::RATE_MONSTER_ATTACK);

               minCombatValue = (int32_t)(it->minCombatValue * multiplier);
               maxCombatValue = (int32_t)(it->maxCombatValue * multiplier);

               it->spell->castSpell(this, attackedCreature);
               if(it->isMelee)
                   extraMeleeAttack = false;
#ifdef __DEBUG__

               static uint64_t prevTicks = OTSYS_TIME();
               std::clog << "doAttacking ticks: " << OTSYS_TIME() - prevTicks << std::endl;
               prevTicks = OTSYS_TIME();
#endif
           }
       }

       if(inRange)
           outOfRange = false;
       else if(it->isMelee) //melee swing out of reach
           extraMeleeAttack = true;
   }

   if(updateLook)
       updateLookDirection();

   if(resetTicks)
       attackTicks = 0;
}
 

Bogart

...has super panda powers
Joined
Jun 21, 2009
Messages
8,010
Best answers
27
Reaction score
532
Location
Panda Land!
In the first two change "return false" to "return null".
In the last two remove the unused variables (displayError and outOfRange) since as the compiler said, they're not being used.
That will solve the warnings and shouldn't affect anything, but don't take my words for it.
 
OP
Noupz

Noupz

New Member
Joined
Jul 13, 2010
Messages
114
Best answers
0
Reaction score
0
i've tryied remove they, but "in the case os luascript" if i remove, the command /town doesn't work
 
Top