[ScryMUD] SVN Commit Info r871 - trunk/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Sun Feb 11 15:23:59 PST 2007


Author: eroper
Date: 2007-02-11 15:23:59 -0800 (Sun, 11 Feb 2007)
New Revision: 871

Modified:
   trunk/mud/grrmud/server/command4.cc
   trunk/mud/grrmud/server/commands.cc
   trunk/mud/grrmud/server/critter.cc
   trunk/mud/grrmud/server/grrmud.cc
   trunk/mud/grrmud/server/mapper.cc
   trunk/mud/grrmud/server/misc.cc
   trunk/mud/grrmud/server/pet_spll.cc
   trunk/mud/grrmud/server/room.cc
   trunk/mud/grrmud/server/skills.cc
Log:
This commit adds initialization for some variables that could have potentially
(through conditionals) been referenced prior to assignment. In addition, this
catches a few locations where pointers were being dereferenced prior to
initialization (guaranteed to happen in some cases).


Modified: trunk/mud/grrmud/server/command4.cc
===================================================================
--- trunk/mud/grrmud/server/command4.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/command4.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -338,9 +338,9 @@
    }//if
 
    Cell<object*> mcll(ptr->inv);
-   object* iptr;
+   object *iptr = NULL;
    int i;
-   for (i=0; iptr != NULL; i++, iptr = mcll.next()) {
+   for (i=0, iptr = mcll.next(); iptr != NULL; i++, iptr = mcll.next()) {
       if (iptr == msg)
          break;
    }//for

Modified: trunk/mud/grrmud/server/commands.cc
===================================================================
--- trunk/mud/grrmud/server/commands.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/commands.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -1274,7 +1274,7 @@
    object* bag_ptr, *tmp;
    object* vict_ptr;
    short item_in_inv=TRUE, bag_in_inv=TRUE, bag_on_person=FALSE, found_it=FALSE;
-   short x;
+   short x = 0;
 
    mudlog.log(DBG, "In put\n");
 
@@ -1455,7 +1455,7 @@
    object* vict_ptr = NULL;
    object* tmp = NULL;;
    short bag_in_inv = TRUE, bag_on_person = FALSE, found_it = FALSE;
-   short x;
+   short x = 0;
    Cell<object*>  cell;
    short tst = FALSE;
 

Modified: trunk/mud/grrmud/server/critter.cc
===================================================================
--- trunk/mud/grrmud/server/critter.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/critter.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -2384,7 +2384,7 @@
 int critter::getHIT(bool include_modifiers=false, object* weapon = NULL) {
    int p_lrnd;
    int modifier = 0;
-   int weapon_skill;
+   int weapon_skill = 0;
 
    if ( include_modifiers && pc ) {
 
@@ -2418,7 +2418,7 @@
 int critter::getWeapDAM(int position, bool include_modifiers=false) {
    int count = 0;
    int sides = 0;
-   int weapon_skill;
+   int weapon_skill = 0;
    int p_lrnd;
    object *weapon = EQ[position];
 

Modified: trunk/mud/grrmud/server/grrmud.cc
===================================================================
--- trunk/mud/grrmud/server/grrmud.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/grrmud.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -1014,7 +1014,7 @@
                String tmp;
                int i;
                int imax;
-               unsigned char telnet_cmd;
+               unsigned char telnet_cmd = '\0';
 
                // Process telnet protocol commands
 

Modified: trunk/mud/grrmud/server/mapper.cc
===================================================================
--- trunk/mud/grrmud/server/mapper.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/mapper.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -358,6 +358,7 @@
                          const direction placement_dir, int distance) {
    int shift_by;
    int x, y, z;
+   x = y = z = 0;
 
    //shift_by is 0 if we don't need to shift and the calls to shift_?? below
    //will return immediately if passed a 0.

Modified: trunk/mud/grrmud/server/misc.cc
===================================================================
--- trunk/mud/grrmud/server/misc.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/misc.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -2854,7 +2854,8 @@
 {
 
    static String output;
-   char *i, *colstrWhich;
+   char *i = NULL;
+   char *colstrWhich = NULL;
    short dont_reset = FALSE;
 
    const char *validFGColorCodes = "0nrgybmcwNRGYBMCW";
@@ -3187,16 +3188,16 @@
 
 int verifydoors(int i_th, critter &pc) {
    Cell<door*> dcell;
-   room* rm_ptr;
-   door* dr_ptr;
-   door* dst_dr_ptr;
+   room* rm_ptr = NULL;
+   door* dr_ptr = NULL;
+   door* dst_dr_ptr = NULL;
    int cur_rm_num;
    int chk_rm_num;
    String buf;
    int i;
    int dir_okay = 0;
-   String *dr_dir;
-   String *dst_dir;
+   String *dr_dir = NULL;
+   String *dst_dir = NULL;
 
    if (! ok_to_do_action(NULL, "I", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
       return -1;

Modified: trunk/mud/grrmud/server/pet_spll.cc
===================================================================
--- trunk/mud/grrmud/server/pet_spll.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/pet_spll.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -382,10 +382,12 @@
 
 
 void cast_mass_charm(critter& pc) {
-   critter* ptr;
    int spell_num = MASS_CHARM_SKILL_NUM;
 
-   if (!ok_to_do_action(ptr, "KMSNV", spell_num, pc)) {
+   //TODO: track down how ok_to_do_action handles getting a NULL vict ptr.
+   // either way, this is better than passing the uninitialized pointer that
+   // it was handing out before
+   if (!ok_to_do_action(NULL, "KMSNV", spell_num, pc)) {
       return;
    }//if
 

Modified: trunk/mud/grrmud/server/room.cc
===================================================================
--- trunk/mud/grrmud/server/room.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/room.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -2526,7 +2526,8 @@
 }
 
 int room::doMload(int i_th) {
-   critter* crit_ptr; 
+   //TODO: Figure out what happens if the following conditional isn't true. --eroper
+   critter* crit_ptr = NULL; 
 
    if ((i_th >= 1) && (i_th < NUMBER_OF_MOBS)) {
       crit_ptr = &(mob_list[i_th]);

Modified: trunk/mud/grrmud/server/skills.cc
===================================================================
--- trunk/mud/grrmud/server/skills.cc	2007-02-11 22:27:35 UTC (rev 870)
+++ trunk/mud/grrmud/server/skills.cc	2007-02-11 23:23:59 UTC (rev 871)
@@ -1361,7 +1361,6 @@
 int scribe(const String* spell, critter& pc, short do_mob) {
    String buf(100);
    object* pen, *parchment; 
-   int spell_num;
 
    /* default is that mob's can't scribe, ie no 'ordering' them to scribe */
    if (!pc.pc && !do_mob)
@@ -1382,6 +1381,8 @@
       return -1;
    }//if
 
+   int spell_num = SSCollection::instance().getNumForName(*spell);
+
    if (!ok_to_do_action(NULL, "mBFPr", spell_num, pc)) {
       return -1;
    }
@@ -1402,7 +1403,6 @@
 
                 // parchment and pen are valid, check on spell //
 
-   spell_num = SSCollection::instance().getNumForName(*spell);
    if (spell_num == -1) {
       show("That spell is in need of research.\n", pc);
       return -1;




More information about the ScryMUD mailing list