From 488b2888a8123341767684ed7ce0cd83a774dcee Mon Sep 17 00:00:00 2001 From: j883376 Date: Tue, 25 Jun 2013 23:40:05 -0400 Subject: [PATCH] Fix uses of uninitialized variables - Replace unknown008 array with two separate variables in Object code - Fix mismatched safe_delete() of an array --- common/eq_packet_structs.h | 3 ++- common/patches/RoF.cpp | 2 -- common/patches/SoD.cpp | 2 -- common/patches/SoF.cpp | 2 -- common/patches/Underfoot.cpp | 2 -- zone/command.cpp | 40 +++++++++++++++++------------------ zone/merc.cpp | 2 +- zone/mob.cpp | 4 +++- zone/zone.cpp | 41 ++++++++++++++++++++---------------- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/common/eq_packet_structs.h b/common/eq_packet_structs.h index f72b4c721..f5bc21a5d 100644 --- a/common/eq_packet_structs.h +++ b/common/eq_packet_structs.h @@ -2415,7 +2415,8 @@ struct BookRequest_Struct { */ struct Object_Struct { /*00*/ uint32 linked_list_addr[2];// They are, get this, prev and next, ala linked list -/*08*/ uint16 unknown008[2]; // +/*08*/ uint16 unknown008; // +/*10*/ uint16 unknown010; // /*12*/ uint32 drop_id; // Unique object id for zone /*16*/ uint16 zone_id; // Redudant, but: Zone the object appears in /*18*/ uint16 zone_instance; // diff --git a/common/patches/RoF.cpp b/common/patches/RoF.cpp index 03893086c..905600821 100644 --- a/common/patches/RoF.cpp +++ b/common/patches/RoF.cpp @@ -3037,7 +3037,6 @@ ENCODE(OP_ZonePlayerToBind) ZonePlayerToBind_Struct *zps = (ZonePlayerToBind_Struct*)(*p)->pBuffer; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); unsigned char *buffer1 = new unsigned char[sizeof(structs::ZonePlayerToBindHeader_Struct) + strlen(zps->zone_name)]; structs::ZonePlayerToBindHeader_Struct *zph = (structs::ZonePlayerToBindHeader_Struct*)buffer1; @@ -4839,7 +4838,6 @@ char* SerializeItem(const ItemInst *inst, int16 slot_id_in, uint32 *length, uint charges = 0xFFFFFFFF; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); const Item_Struct *item = inst->GetItem(); //_log(NET__ERROR, "Serialize called for: %s", item->Name); diff --git a/common/patches/SoD.cpp b/common/patches/SoD.cpp index ce0a3566f..517479b48 100644 --- a/common/patches/SoD.cpp +++ b/common/patches/SoD.cpp @@ -1984,7 +1984,6 @@ ENCODE(OP_ZonePlayerToBind) ZonePlayerToBind_Struct *zps = (ZonePlayerToBind_Struct*)(*p)->pBuffer; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); unsigned char *buffer1 = new unsigned char[sizeof(structs::ZonePlayerToBindHeader_Struct) + strlen(zps->zone_name)]; structs::ZonePlayerToBindHeader_Struct *zph = (structs::ZonePlayerToBindHeader_Struct*)buffer1; @@ -3057,7 +3056,6 @@ char* SerializeItem(const ItemInst *inst, int16 slot_id_in, uint32 *length, uint charges = 0xFFFFFFFF; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); const Item_Struct *item = inst->GetItem(); //_log(NET__ERROR, "Serialize called for: %s", item->Name); diff --git a/common/patches/SoF.cpp b/common/patches/SoF.cpp index e5e144224..b7e1dac2f 100644 --- a/common/patches/SoF.cpp +++ b/common/patches/SoF.cpp @@ -1621,7 +1621,6 @@ ENCODE(OP_ZonePlayerToBind) ZonePlayerToBind_Struct *zps = (ZonePlayerToBind_Struct*)(*p)->pBuffer; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); unsigned char *buffer1 = new unsigned char[sizeof(structs::ZonePlayerToBindHeader_Struct) + strlen(zps->zone_name)]; structs::ZonePlayerToBindHeader_Struct *zph = (structs::ZonePlayerToBindHeader_Struct*)buffer1; @@ -2376,7 +2375,6 @@ char* SerializeItem(const ItemInst *inst, int16 slot_id_in, uint32 *length, uint charges = 0xFFFFFFFF; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); const Item_Struct *item = inst->GetItem(); //_log(NET__ERROR, "Serialize called for: %s", item->Name); diff --git a/common/patches/Underfoot.cpp b/common/patches/Underfoot.cpp index 041f483a5..2a8b57aa5 100644 --- a/common/patches/Underfoot.cpp +++ b/common/patches/Underfoot.cpp @@ -2044,7 +2044,6 @@ ENCODE(OP_ZonePlayerToBind) ZonePlayerToBind_Struct *zps = (ZonePlayerToBind_Struct*)(*p)->pBuffer; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); unsigned char *buffer1 = new unsigned char[sizeof(structs::ZonePlayerToBindHeader_Struct) + strlen(zps->zone_name)]; structs::ZonePlayerToBindHeader_Struct *zph = (structs::ZonePlayerToBindHeader_Struct*)buffer1; @@ -3462,7 +3461,6 @@ char* SerializeItem(const ItemInst *inst, int16 slot_id_in, uint32 *length, uint charges = 0xFFFFFFFF; std::stringstream ss(std::stringstream::in | std::stringstream::out | std::stringstream::binary); - ss.clear(); const Item_Struct *item = inst->GetItem(); //_log(NET__ERROR, "Serialize called for: %s", item->Name); diff --git a/zone/command.cpp b/zone/command.cpp index b08fe3104..625278eee 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -9696,22 +9696,22 @@ void command_object(Client *c, const Seperator *sep) od.object_type = atoi(row[col++]); icon = atoi(row[col++]); - od.unknown008[0] = atoi(row[col++]); - od.unknown008[1] = atoi(row[col++]); + od.unknown008 = atoi(row[col++]); + od.unknown010 = atoi(row[col++]); od.unknown020 = atoi(row[col++]); switch (od.object_type) { case 0: // Static Object case TempStaticType: // Static Object unlocked for changes - if (od.unknown008[0] == 0) // Unknown08 field is optional Size parameter for static objects + if (od.unknown008 == 0) // Unknown08 field is optional Size parameter for static objects { - od.unknown008[0] = 100; // Static object default Size is 100% + od.unknown008 = 100; // Static object default Size is 100% } c->Message(0, "- STATIC Object (%s): id %u, x %.1f, y %.1f, z %.1f, h %.1f, model %s, size %u, solidtype %u, incline %u", - (od.object_type == 0) ? "locked" : "unlocked", id, od.x, od.y, od.z, od.heading, od.object_name, od.unknown008[0], od.unknown008[1], od.unknown020); + (od.object_type == 0) ? "locked" : "unlocked", id, od.x, od.y, od.z, od.heading, od.object_name, od.unknown008, od.unknown010, od.unknown020); break; case OT_DROPPEDITEM: // Ground Spawn c->Message(0, @@ -9777,11 +9777,11 @@ void command_object(Client *c, const Seperator *sep) case 0: // Static Object if ((sep->argnum - col) > 3) { - od.unknown008[0] = atoi(sep->arg[4 + col]); // Size specified + od.unknown008 = atoi(sep->arg[4 + col]); // Size specified if ((sep->argnum - col) > 4) { - od.unknown008[1] = atoi(sep->arg[5 + col]); // SolidType specified + od.unknown010 = atoi(sep->arg[5 + col]); // SolidType specified if ((sep->argnum - col) > 5) { @@ -10168,15 +10168,15 @@ void command_object(Client *c, const Seperator *sep) return; } - od.unknown008[0] = atoi(sep->arg[4]); + od.unknown008 = atoi(sep->arg[4]); o->SetObjectData(&od); - if (od.unknown008[0] == 0) // 0 == unspecified == 100% + if (od.unknown008 == 0) // 0 == unspecified == 100% { - od.unknown008[0] = 100; + od.unknown008 = 100; } - c->Message(0, "Static Object %u set to %u%% size. Size will take effect when you commit to the database with '#object Save', after which the object will be unchangeable until you unlock it again with '#object Edit' and zone out and back in.", id, od.unknown008[0]); + c->Message(0, "Static Object %u set to %u%% size. Size will take effect when you commit to the database with '#object Save', after which the object will be unchangeable until you unlock it again with '#object Edit' and zone out and back in.", id, od.unknown008); } else if (strcmp(sep->arg[3], "solidtype") == 0) { @@ -10194,10 +10194,10 @@ void command_object(Client *c, const Seperator *sep) return; } - od.unknown008[1] = atoi(sep->arg[4]); + od.unknown010 = atoi(sep->arg[4]); o->SetObjectData(&od); - c->Message(0, "Static Object %u set to SolidType %u. Change will take effect when you commit to the database with '#object Save'. Support for this property is on a per-model basis, mostly seen in smaller objects such as chests and tables.", id, od.unknown008[1]); + c->Message(0, "Static Object %u set to SolidType %u. Change will take effect when you commit to the database with '#object Save'. Support for this property is on a per-model basis, mostly seen in smaller objects such as chests and tables.", id, od.unknown010); } else { @@ -10548,7 +10548,7 @@ void command_object(Client *c, const Seperator *sep) zone->GetZoneID(), zone->GetInstanceVersion(), od.x, od.y, od.z, od.heading, od.object_name, od.object_type, icon, - od.unknown008[0], od.unknown008[1], od.unknown020); + od.unknown008, od.unknown010, od.unknown020); } else { @@ -10558,7 +10558,7 @@ void command_object(Client *c, const Seperator *sep) id, zone->GetZoneID(), zone->GetInstanceVersion(), od.x, od.y, od.z, od.heading, od.object_name, od.object_type, icon, - od.unknown008[0], od.unknown008[1], od.unknown020); + od.unknown008, od.unknown010, od.unknown020); } } else @@ -10573,7 +10573,7 @@ void command_object(Client *c, const Seperator *sep) zone->GetZoneID(), zone->GetInstanceVersion(), od.x, od.y, od.z, od.heading, od.object_name, od.object_type, icon, - od.unknown008[0], od.unknown008[1], od.unknown020, + od.unknown008, od.unknown010, od.unknown020, id); } @@ -10651,12 +10651,12 @@ void command_object(Client *c, const Seperator *sep) memcpy(door.dest_zone, "NONE", 5); - if ((door.size = od.unknown008[0]) == 0) // unknown08 = optional size percentage + if ((door.size = od.unknown008) == 0) // unknown08 = optional size percentage { door.size = 100; } - switch (door.opentype = od.unknown008[1]) // unknown10 = optional request_nonsolid (0 or 1 or experimental number) + switch (door.opentype = od.unknown010) // unknown10 = optional request_nonsolid (0 or 1 or experimental number) { case 0: door.opentype = 31; @@ -10943,8 +10943,8 @@ void command_object(Client *c, const Seperator *sep) strn0cpy(od.object_name, row[col++], sizeof(od.object_name)); od.object_type = atoi(row[col++]); icon = atoi(row[col++]); - od.unknown008[0] = atoi(row[col++]); - od.unknown008[1] = atoi(row[col++]); + od.unknown008 = atoi(row[col++]); + od.unknown010 = atoi(row[col++]); od.unknown020 = atoi(row[col++]); if (od.object_type == 0) diff --git a/zone/merc.cpp b/zone/merc.cpp index 0e262f735..fb23cfc12 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5786,7 +5786,7 @@ bool Merc::AddMercToGroup(Merc* merc, Group* group) { void Client::InitializeMercInfo() { for(int i=0; iLoadProximities(zoneid); }