Jump to content

[patch, Crashfix][5719] Unit.cpp Erroneous Unit Type Verification Fix


Guest Alex/AT
 Share

Recommended Posts

Unit.cpp contains small mistake which can cause wrong object typization and calls to non-existent methods when the object is player and it has no group.

Look:

if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())

will fail if unit is not TYPEID_PLAYER or if it has no group. In both cases it goes to else, and then:

if(((Creature*)this)->isPet())

executes. When unit is TYPEID_PLAYER without group, it is (Player*) and has no isPet function. Calls to nowhere are surely bad :)

Fix here [4692+]:

--- src/game/Unit.cpp     2008-04-27 12:40:49.000000000 +0400
+++ src/game/Unit.cpp     2008-04-27 20:52:05.000000000 +0400
@@ -6193,8 +6193,11 @@
{
        SetByteValue(UNIT_FIELD_BYTES_0, 3, new_powertype);

-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9014,8 +9020,11 @@
        SetUInt32Value(UNIT_FIELD_HEALTH, val);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9033,8 +9042,11 @@
        SetUInt32Value(UNIT_FIELD_MAXHEALTH, val);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9058,8 +9070,11 @@
        SetStatInt32Value(UNIT_FIELD_POWER1 + power, val);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9077,8 +9092,11 @@
        SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9098,8 +9116,11 @@
        ApplyModUInt32Value(UNIT_FIELD_POWER1+power, val, apply);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);
@@ -9116,8 +9137,11 @@
        ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1+power, val, apply);

        // group update
-        if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup())
+        if (GetTypeId() == TYPEID_PLAYER)
+        {
+             if (((Player*)this)->GetGroup())
                ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER);
+        }
        else if(((Creature*)this)->isPet())
        {
                Pet *pet = ((Pet*)this);

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use