TrinityCore/TrinityCore — Issue #4818: [Fix] Compile warnings
Author: Elron103
Created: 2012-01-14 16:25:38+00:00
State: open

Hey there,

compiling a new TrinityCore version, I noticed several compiler warnings.

#== Versions ==
* TrinityCore: https://github.com/TrinityCore/TrinityCore/commit/be871b2e350870462fd576ba85e27c7bdac8cdbc + several custom modifications
* CMake for Windows: 2.8.6
* Compiler: Microsoft Visual Studio C++ Express 2008

#== Description / Fix Explanation ==
The most important compile warnings have been introduced in revision:
https://github.com/TrinityCore/TrinityCore/commit/72675d55d821e0648c53d53d78a1690276103c8c

The variable "uint16 index = 0;" is passed to a function, which expects a uint8 variable. This causes the compile warning:

11>..\..\..\..\src\server\game\Entities\Player\Player.cpp(18482) : warning C4244: 'argument' : conversion from 'uint16' to 'const uint8', possible loss of data

It is safe to change the variable type to uint8 because the maximum value of index will be 62. The if ... else structure of the code keeps the maximum number that low.

There are several other warnings, which are mostly caused by a conversion of floats => ints or times => ints. It is always safe to force the conversion there.

As it seems, the warnings are not fixed until now.

#== Fix ==
```diff
diff -r be294833591f src/server/game/Entities/Pet/Pet.cpp
--- a/src/server/game/Entities/Pet/Pet.cpp	Sat Jan 14 17:07:58 2012 +0100
+++ b/src/server/game/Entities/Pet/Pet.cpp	Sat Jan 14 17:11:44 2012 +0100
@@ -906,7 +906,7 @@
SetCreateHealth(40*petlevel);
SetCreateMana(28 + 10*petlevel);
}
- SetBonusDamage(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FIRE) * 0.5f);
+ SetBonusDamage((int32)(m_owner->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FIRE) * 0.5f));
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 4 - petlevel));
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 4 + petlevel));
break;
diff -r be294833591f src/server/game/Entities/Player/Player.cpp
--- a/src/server/game/Entities/Player/Player.cpp	Sat Jan 14 17:07:58 2012 +0100
+++ b/src/server/game/Entities/Player/Player.cpp	Sat Jan 14 17:11:44 2012 +0100
@@ -18472,7 +18472,7 @@
outDebugValues();

PreparedStatement* stmt = NULL;
- uint16 index = 0;
+ uint8 index = 0;

if (create)
{
@@ -18511,12 +18511,12 @@
//save, far from tavern/city
//save, but in tavern/city
stmt->setUInt32(index++, m_resetTalentsCost);
- stmt->setUInt32(index++, m_resetTalentsTime);
+ stmt->setUInt32(index++, (uint32)m_resetTalentsTime);
stmt->setUInt16(index++, (uint16)m_ExtraFlags);
stmt->setUInt8(index++, m_stableSlots);
stmt->setUInt16(index++, (uint16)m_atLoginFlags);
stmt->setUInt16(index++, GetZoneId());
- stmt->setUInt32(index++, m_deathExpireTime);
+ stmt->setUInt32(index++, (uint32)m_deathExpireTime);

ss.str("");
ss << m_taxi.SaveTaxiDestinationsToString();
@@ -18622,12 +18622,12 @@
//save, far from tavern/city
//save, but in tavern/city
stmt->setUInt32(index++, m_resetTalentsCost);
- stmt->setUInt32(index++, m_resetTalentsTime);
+ stmt->setUInt32(index++, (uint32)m_resetTalentsTime);
stmt->setUInt16(index++, (uint16)m_ExtraFlags);
stmt->setUInt8(index++, m_stableSlots);
stmt->setUInt16(index++, (uint16)m_atLoginFlags);
stmt->setUInt16(index++, GetZoneId());
- stmt->setUInt32(index++, m_deathExpireTime);
+ stmt->setUInt32(index++, (uint32)m_deathExpireTime);

ss.str("");
ss << m_taxi.SaveTaxiDestinationsToString();
diff -r be294833591f src/server/game/Instances/InstanceSaveMgr.cpp
--- a/src/server/game/Instances/InstanceSaveMgr.cpp	Sat Jan 14 17:07:58 2012 +0100
+++ b/src/server/game/Instances/InstanceSaveMgr.cpp	Sat Jan 14 17:11:44 2012 +0100
@@ -580,7 +580,7 @@
if (period < DAY)
period = DAY;

- uint32 next_reset = ((resetTime + MINUTE) / DAY * DAY) + period + diff;
+ uint32 next_reset = (uint32)(((resetTime + MINUTE) / DAY * DAY) + period + diff);

SetResetTimeFor(mapid, difficulty, next_reset);
ScheduleReset(true, time_t(next_reset-3600), InstResetEvent(1, mapid, difficulty, 0));
diff -r be294833591f src/server/scripts/Outland/blades_edge_mountains.cpp
--- a/src/server/scripts/Outland/blades_edge_mountains.cpp	Sat Jan 14 17:07:58 2012 +0100
+++ b/src/server/scripts/Outland/blades_edge_mountains.cpp	Sat Jan 14 17:11:44 2012 +0100
@@ -781,7 +781,7 @@
colorSequence.clear();
playableSequence.clear();
playerSequence.clear();
- me->SetFloatValue(OBJECT_FIELD_SCALE_X, large ? 2 : 1);
+ me->SetFloatValue(OBJECT_FIELD_SCALE_X, large ? 2.0f : 1.0f);

std::list ClusterList;
Trinity::AllWorldObjectsInRange objects(me, searchDistance);
```